Nakalchi ReportsAdmin

← Back to analysis

var_b vs var_f

FLAGGED

Problem: two-sum

A→B62%B→A46%Shared fingerprints26
90tokens in the longest matched region
var_b
#include <bits/stdc++.h>
using namespace std;

// Solution to the two-sum problem
// Approach: single pass with a hash map
// Time complexity: O(n) average

int main()
{
    // fast input
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;              // number of elements
    long long t;        // the target sum
    cin >> n >> t;

    // maps value -> 1-based index where we saw it
    unordered_map<long long, int> seen;
    seen.reserve(n * 2);        // avoid rehashing

    for (int idx = 1; idx <= n; idx++)
    {
        long long x;
        cin >> x;   // read next number

        // did we already see the complement?
        auto it = seen.find(t - x);
        if (it != seen.end())
        {
            // yes -> print the pair and stop
            cout << it->second << ' ' << idx << '\n';
            return 0;
        }

        seen[x] = idx;  // remember this value
    }
    return 0;   // per the guarantee we never get here
}
var_f
#include <bits/stdc++.h>
using namespace std;

static int runs = 0;

void banner() {
    // deliberately original code around the lifted part
    runs++;
}

// ---- lifted from the original solution (this is the copied part) ----
int solve(int n, long long t) {
    unordered_map<long long, int> seen;
    seen.reserve(n * 2);
    for (int idx = 1; idx <= n; idx++) {
        long long x;
        cin >> x;
        auto it = seen.find(t - x);
        if (it != seen.end()) {
            cout << it->second << ' ' << idx << '\n';
            return 0;
        }
        seen[x] = idx;
    }
    return 1;
}
// ---------------------------------------------------------------------

int main() {
    banner();
    int n; long long t;
    if (!(cin >> n >> t)) return 1;
    int status = solve(n, t);
    banner();
    return status == 0 ? 0 : 2;
}