Submission #477350

#TimeUsernameProblemLanguageResultExecution timeMemory
477350BTheroCards (LMIO19_korteles)C++17
36 / 100
1092 ms46788 KiB
#include <bits/stdc++.h> #define pb push_back #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() using namespace std; typedef long long ll; const int MAXN = (int)5e5 + 5; array<int, 4> arr[MAXN]; map<ll, int> cnt[16]; int n; int encode(char a, char b) { return (a - 'A') * 26 + (b - 'A'); } bool bit(int x, int p) { return x & (1 << p); } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 0; i < n; i++) { string x, y; cin >> x >> y; arr[i][0] = encode(x[0], x[1]); arr[i][1] = encode(x[0], y[0]); arr[i][2] = encode(x[1], y[1]); arr[i][3] = encode(y[0], y[1]); } ll ans = 0; for (int i = 0; i < n; i++) { for (int mask = 1; mask < 16; mask++) { ll cur = 0; for (int j = 0; j < 4; j++) { if (bit(mask, j)) { cur = cur * 26 * 26 + arr[i][j]; } } int pp = __builtin_popcount(mask); auto it = cnt[mask].find(cur); ll tmp = (it == cnt[mask].end() ? 0 : it -> second); if (pp % 2 == 1) { ans += tmp; } else { ans -= tmp; } } reverse(all(arr[i])); for (int mask = 1; mask < 16; mask++) { ll cur = 0; for (int j = 0; j < 4; j++) { if (bit(mask, j)) { cur = cur * 26 * 26 + arr[i][j]; } } cnt[mask][cur]++; } } cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...