var_e vs var_f
Problem: two-sum
A→B9%B→A9%Shared fingerprints5
24tokens in the longest matched region
var_e
#include <bits/stdc++.h>
using namespace std;
// two-sum, hash map approach, O(n) expected
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int total; // element count
long long goal; // required sum
cin >> total >> goal;
unordered_map<long long, int> prior; // value -> earliest index
prior.reserve(2 * total);
int pos = 1;
while (pos <= total) {
long long cur;
cin >> cur; // next value
long long complement = goal - cur;
auto hit = prior.find(complement);
if (prior.end() != hit) {
// found the partner we stored earlier
cout << hit->second << ' ' << pos << '\n';
return 0;
}
prior[cur] = pos; // stash for later
pos = pos + 1;
}
return 0;
}
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;
}