Nakalchi ReportsAdmin

← Back to analysis

sol02 vs var_c

FLAGGED

Problem: two-sum

A→B48%B→A37%Shared fingerprints20
49tokens in the longest matched region
sol02
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; long long t;
    cin >> n >> 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 0;
}
var_c
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; long long t;
    cin >> n >> t;
    unordered_map<long long, int> seen;
    seen.reserve(2 * n);
    int idx = 1;
    while (idx <= n) {
        long long x;
        cin >> x;
        long long need = t - x;
        auto it = seen.find(need);
        if (seen.end() != it) {
            cout << it->second << ' ' << idx << '\n';
            return 0;
        }
        seen[x] = idx;
        idx = idx + 1;
    }
    return 0;
}