Submission #895562

# Submission time Handle Problem Language Result Execution time Memory
895562 2023-12-30T09:14:48 Z vjudge1 Cards (LMIO19_korteles) C++17
100 / 100
734 ms 45660 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";
}
# Verdict Execution time Memory Grader output
1 Correct 12 ms 45660 KB Output is correct
2 Correct 11 ms 45400 KB Output is correct
3 Correct 11 ms 45256 KB Output is correct
4 Correct 11 ms 45400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 45660 KB Output is correct
2 Correct 11 ms 45400 KB Output is correct
3 Correct 11 ms 45256 KB Output is correct
4 Correct 11 ms 45400 KB Output is correct
5 Correct 11 ms 45404 KB Output is correct
6 Correct 12 ms 45224 KB Output is correct
7 Correct 13 ms 45404 KB Output is correct
8 Correct 15 ms 45256 KB Output is correct
9 Correct 15 ms 45404 KB Output is correct
10 Correct 15 ms 45220 KB Output is correct
11 Correct 11 ms 45400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 722 ms 45440 KB Output is correct
2 Correct 712 ms 45652 KB Output is correct
3 Correct 703 ms 45648 KB Output is correct
4 Correct 734 ms 45444 KB Output is correct
5 Correct 698 ms 45404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 45400 KB Output is correct
2 Correct 90 ms 45404 KB Output is correct
3 Correct 462 ms 45440 KB Output is correct
4 Correct 287 ms 45440 KB Output is correct
5 Correct 273 ms 45436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 45404 KB Output is correct
2 Correct 12 ms 45224 KB Output is correct
3 Correct 13 ms 45404 KB Output is correct
4 Correct 15 ms 45256 KB Output is correct
5 Correct 15 ms 45404 KB Output is correct
6 Correct 15 ms 45220 KB Output is correct
7 Correct 11 ms 45400 KB Output is correct
8 Correct 12 ms 45660 KB Output is correct
9 Correct 11 ms 45400 KB Output is correct
10 Correct 11 ms 45256 KB Output is correct
11 Correct 11 ms 45400 KB Output is correct
12 Correct 722 ms 45440 KB Output is correct
13 Correct 712 ms 45652 KB Output is correct
14 Correct 703 ms 45648 KB Output is correct
15 Correct 734 ms 45444 KB Output is correct
16 Correct 698 ms 45404 KB Output is correct
17 Correct 90 ms 45404 KB Output is correct
18 Correct 462 ms 45440 KB Output is correct
19 Correct 287 ms 45440 KB Output is correct
20 Correct 273 ms 45436 KB Output is correct
21 Correct 168 ms 45440 KB Output is correct
22 Correct 568 ms 45652 KB Output is correct
23 Correct 363 ms 45456 KB Output is correct
24 Correct 357 ms 45444 KB Output is correct