Submission #320194

#TimeUsernameProblemLanguageResultExecution timeMemory
320194Karen124PIN (CEOI10_pin)C++14
15 / 100
1046 ms107492 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const ll N = 5e5 + 5; const ll INF = 1e18 + 10; int n, d, ans; string a[N], b; unordered_map <string, int> cn; char add[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'g', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'x'}; int f(string s1, string s2){ int ret = 0; for (int i = 0; i < 4; i++){ ret += (s1[i] != s2[i]); } return ret; } int main (){ cin >> n >> d; if (n <= 2000){ for (int i = 0; i < n; i++){ cin >> a[i]; for (int j = 0; j < i; j++){ ans += (f(a[i], a[j]) == d); } } cout << ans << '\n'; return 0; } if (d == 1) for (int i = 0; i < n; i++){ cin >> a[i]; for (int j = 0; j < 36; j++){ if (add[j] == a[i][0]) continue; b = a[i]; b[0] = add[j]; ans += cn[b]; } for (int j = 0; j < 36; j++){ if (add[j] == a[i][1]) continue; b = a[i]; b[1] = add[j]; } for (int j = 0; j < 36; j++){ if (add[j] == a[i][2]) continue; b = a[i]; b[2] = add[j]; ans += cn[b]; } for (int j = 0; j < 36; j++){ if (add[j] == a[i][3]) continue; b = a[i]; b[3] = add[j]; ans += cn[b]; } cn[a[i]] ++; } cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...