Submission #254185

#TimeUsernameProblemLanguageResultExecution timeMemory
254185BertedCards (LMIO19_korteles)C++14
100 / 100
283 ms2424 KiB
#include <iostream> #define ll long long using namespace std; int n, ar[4][700], ar2[4][700], ar3[500001]; ll res = 0; inline int getHash1(char a, char b) { return (a - 'A') * 26 + (b - 'A'); } inline int getHash2(char a, char b, char c, char d) { return (a - 'A') * 17576 + (b - 'A') * 676 + (c - 'A') * 26 + (d - 'A'); } int main() { cin >> n; for (int i = 0; i < n; i++) { string a, b; cin >> a >> b; res += ar[0][getHash1(b[0], b[1])]; res += ar[1][getHash1(a[1], b[1])]; res += ar[2][getHash1(a[0], a[1])]; res += ar[3][getHash1(a[0], b[0])]; ar[0][getHash1(a[0], a[1])]++; ar[1][getHash1(a[0], b[0])]++; ar[2][getHash1(b[0], b[1])]++; ar[3][getHash1(a[1], b[1])]++; if (a[1] == b[0]) { res -= ar2[0][getHash1(a[0], b[0])]; res -= ar2[2][getHash1(a[1], b[1])]; ar2[0][getHash1(a[1], b[1])]++; ar2[2][getHash1(a[0], b[0])]++; } if (a[0] == b[1]) { res -= ar2[1][getHash1(a[1], b[1])]; res -= ar2[3][getHash1(a[0], b[0])]; ar2[1][getHash1(a[0], b[0])]++; ar2[3][getHash1(a[1], b[1])]++; } res -= ar3[getHash2(a[1], a[0], b[1], b[0])]; res -= ar3[getHash2(b[0], b[1], a[0], a[1])]; if (a[0] == b[1] && a[1] == b[0]) { res += 3 * ar3[getHash2(a[1], a[0], a[0], a[1])]; } ar3[getHash2(a[0], a[1], b[0], b[1])]++; } cout << res << "\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...