답안 #895561

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
895561 2023-12-30T09:14:29 Z d4xn Cards (LMIO19_korteles) C++17
100 / 100
745 ms 48212 KB
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math,inline")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,lzcnt,mmx,abm,avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;

#define all(x) x.begin(), x.end()
#define tp4 tuple<int, int, int, int>

const int N = 456976, D = 27, inf = INT_MAX;

int n, ans, dp[D][D][D][D];
string a[2][N], b[N];

signed main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);

  for (int i = 0; i < D; i++) {
    for (int j = 0; j < D; j++) {
      for (int k = 0; k < D; k++) {
        memset(dp[i][j][k], 0, sizeof(dp[i][j][k]));
      }
    }
  }

  vector<tp4> comb(4);
  comb[0] = make_tuple(0, 1, 2, 3);
  comb[1] = make_tuple(1, 3, 0, 2);
  comb[2] = make_tuple(0, 2, 1, 3);
  comb[3] = make_tuple(2, 3, 0, 1);

  cin >> n;
  ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[0][i] >> a[1][i];
    b[i] = a[0][i] + a[1][i];

    // con cuantas de antes combina esta carta?

    for (int mask = 1; mask < (1 << 4); mask++) {
      vector<int> eq[4];
      for (int j = 0; j < 4; j++) {
        if (!((mask >> j) & 1)) continue;
        eq[get<2>(comb[j])].push_back(get<0>(comb[j]));
        eq[get<3>(comb[j])].push_back(get<1>(comb[j]));
      }
 
      bool ok = 1;
      int nwEq[4] = {D-1, D-1, D-1, D-1};
      for (int j = 0; j < 4 && ok; j++) {
        int sz = eq[j].size();
        for (int k = 1; k < sz; k++) {
          //cerr << j << " eq " << eq[j][k] << endl;
          if (b[i][eq[j][k]] != b[i][eq[j][0]]) {
            ok = 0;
            break;
          }
        }
        if (sz) nwEq[j] = (int)(b[i][eq[j][0]]-'A');
      }
      if (!ok) continue;

      /*cerr << i << " nwEq " << __builtin_popcount(mask) << endl;
      for (int j = 0; j < 4; j++) {
        cerr << nwEq[j] << " ";
      }
      cerr << endl;*/

      ans += dp[nwEq[0]][nwEq[1]][nwEq[2]][nwEq[3]] * (__builtin_popcount(mask)%2 ? 1 : -1);
    }

    // añado esta carta
    for (int mask = 1; mask < (1 << 4); mask++) {
      int x[4];
      //cerr << "x ";
      for (int j = 0; j < 4; j++) {
        x[j] = (((mask >> j) & 1) ? (int)(b[i][j]-'A') : D-1);
        //cerr << x[j] << " ";
      }
      //cerr << endl;
      dp[x[0]][x[1]][x[2]][x[3]]++;
    }//cerr << ans << endl;
  }

  cout << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 45404 KB Output is correct
2 Correct 11 ms 45404 KB Output is correct
3 Correct 11 ms 45404 KB Output is correct
4 Correct 11 ms 45404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 45404 KB Output is correct
2 Correct 11 ms 45404 KB Output is correct
3 Correct 11 ms 45404 KB Output is correct
4 Correct 11 ms 45404 KB Output is correct
5 Correct 13 ms 45404 KB Output is correct
6 Correct 13 ms 45404 KB Output is correct
7 Correct 15 ms 45264 KB Output is correct
8 Correct 15 ms 45404 KB Output is correct
9 Correct 15 ms 45404 KB Output is correct
10 Correct 15 ms 45252 KB Output is correct
11 Correct 12 ms 45404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 711 ms 45436 KB Output is correct
2 Correct 702 ms 48212 KB Output is correct
3 Correct 700 ms 47952 KB Output is correct
4 Correct 745 ms 47988 KB Output is correct
5 Correct 718 ms 48112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 45404 KB Output is correct
2 Correct 87 ms 45404 KB Output is correct
3 Correct 463 ms 45404 KB Output is correct
4 Correct 278 ms 45648 KB Output is correct
5 Correct 273 ms 45404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 45404 KB Output is correct
2 Correct 13 ms 45404 KB Output is correct
3 Correct 15 ms 45264 KB Output is correct
4 Correct 15 ms 45404 KB Output is correct
5 Correct 15 ms 45404 KB Output is correct
6 Correct 15 ms 45252 KB Output is correct
7 Correct 12 ms 45404 KB Output is correct
8 Correct 11 ms 45404 KB Output is correct
9 Correct 11 ms 45404 KB Output is correct
10 Correct 11 ms 45404 KB Output is correct
11 Correct 11 ms 45404 KB Output is correct
12 Correct 711 ms 45436 KB Output is correct
13 Correct 702 ms 48212 KB Output is correct
14 Correct 700 ms 47952 KB Output is correct
15 Correct 745 ms 47988 KB Output is correct
16 Correct 718 ms 48112 KB Output is correct
17 Correct 87 ms 45404 KB Output is correct
18 Correct 463 ms 45404 KB Output is correct
19 Correct 278 ms 45648 KB Output is correct
20 Correct 273 ms 45404 KB Output is correct
21 Correct 164 ms 45948 KB Output is correct
22 Correct 547 ms 47572 KB Output is correct
23 Correct 355 ms 46676 KB Output is correct
24 Correct 371 ms 46788 KB Output is correct