제출 #254133

#제출 시각아이디문제언어결과실행 시간메모리
254133rama_pangCards (LMIO19_korteles)C++14
100 / 100
357 ms33664 KiB
#include <bits/stdc++.h> using namespace std; using lint = long long; const int MAXN = 27 * 27 * 27 * 27; int N; int cnt[MAXN][16]; // NESW inline int Hash(int c[2][2]) { return c[0][0] * 27 * 27 * 27 + c[0][1] * 27 * 27 + c[1][0] * 27 + c[1][1]; } int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); cin >> N; lint ans = 0; for (int cards = 0; cards < N; cards++) { int c[2][2]; int alt[2][2]; int pick[2][2]; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { char a; cin >> a; c[i][j] = a - 'A' + 1; } } for (int mask = 1; mask < 16; mask++) { alt[0][0] = alt[0][1] = alt[1][0] = alt[1][1] = 0; pick[0][0] = pick[0][1] = pick[1][0] = pick[1][1] = 0; int cur = 0; if (mask & (1 << 0)) { // N alt[0][0] |= 1 << (c[1][0]); alt[0][1] |= 1 << (c[1][1]); pick[0][0] |= c[1][0]; pick[0][1] |= c[1][1]; } if (mask & (1 << 1)) { // E alt[0][1] |= 1 << (c[0][0]); alt[1][1] |= 1 << (c[1][0]); pick[0][1] |= c[0][0]; pick[1][1] |= c[1][0]; } if (mask & (1 << 2)) { // S alt[1][0] |= 1 << (c[0][0]); alt[1][1] |= 1 << (c[0][1]); pick[1][0] |= c[0][0]; pick[1][1] |= c[0][1]; } if (mask & (1 << 3)) { // W alt[0][0] |= 1 << (c[0][1]); alt[1][0] |= 1 << (c[1][1]); pick[0][0] |= c[0][1]; pick[1][0] |= c[1][1]; } int can = 1; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { if (alt[i][j] & (alt[i][j] - 1)) { can = 0; } } } if (can) { cur = cnt[Hash(pick)][mask]; } ans += cur; } for (int mask = 1; mask < 16; mask++) { pick[0][0] = pick[0][1] = pick[1][0] = pick[1][1] = 0; if (mask & (1 << 0)) { // N pick[0][0] = c[0][0]; pick[0][1] = c[0][1]; } if (mask & (1 << 1)) { // E pick[0][1] = c[0][1]; pick[1][1] = c[1][1]; } if (mask & (1 << 2)) { // S pick[1][0] = c[1][0]; pick[1][1] = c[1][1]; } if (mask & (1 << 3)) { // W pick[0][0] = c[0][0]; pick[1][0] = c[1][0]; } if (__builtin_popcount(mask) & 1) { cnt[Hash(pick)][mask]++; } else { cnt[Hash(pick)][mask]--; } } } 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...