Submission #254118

#TimeUsernameProblemLanguageResultExecution timeMemory
254118NightlightCards (LMIO19_korteles)C++14
100 / 100
76 ms4096 KiB
#include <bits/stdc++.h> using namespace std; int N; int L[680], R[680], U[680], D[680]; bitset<680> vis1, vis2; long long cnt[500000]; char aa, bb, cc, dd; long long ans; /* AB CD */ inline int num(char A, char B, char C, char D) {return 17576 * (A - 'A') + 676 * (B - 'A') + 26 * (C - 'A') + D - 'A';} inline int num(char C, char D) {return 26 * (C - 'A') + D - 'A';} inline int num(int A, int B, int C, int D) {return 17576 * (A) + 676 * (B) + 26 * (C) + D;} inline int num(int C, int D) {return 26 * (C) + D;} inline void match(int a, int b) {if(a > b) ans -= cnt[a] * cnt[b];} inline void match2(int a, int b) {if(a != b) ans -= cnt[a] * cnt[b];} int main() { ios_base::sync_with_stdio(0); cin >> N; for(int i = 1; i <= N; i++) { cin >> aa >> bb >> cc >> dd; if(aa == bb && cc == dd) ans--; if(aa == cc && bb == dd) ans--; cnt[num(aa, bb, cc, dd)]++; L[num(aa, cc)]++; U[num(aa, bb)]++; R[num(bb, dd)]++; D[num(cc, dd)]++; } // cout << ans << "\n"; for(int i = 0; i < 26; i++) { for(int j = 0; j < 26; j++) { ans += L[num(i, j)] * R[num(i, j)]; ans += U[num(i, j)] * D[num(i, j)]; for(int k = 0; k < 26; k++) { for(int l = 0; l < 26; l++) { match(num(i, j, k, l), num(k, l, i, j)); match(num(i, j, k, l), num(j, i, l, k)); match2(num(i, j, k, i), num(j, l, i, j)); match2(num(k, i, i, j), num(i, j, j, l)); } } if(i < j) ans += 3 * cnt[num(i, j, j, i)] * cnt[num(j, i, i, j)]; } } cout << ans << "\n"; cin >> N; }
#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...