답안 #895558

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
895558 2023-12-30T09:11:00 Z vjudge1 Cards (LMIO19_korteles) C++17
55 / 100
1000 ms 48360 KB
#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<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;
      vector<int> nwEq(4, D-1);
      for (int j = 0; j < 4 && ok; j++) {
        int sz = eq[j].size();
        for (int k = 0; k < sz && ok; k++) {
          //cerr << j << " eq " << eq[j][k] << endl;
          if (b[i][eq[j][k]] != b[i][eq[j][0]]) ok = 0;
        }
        if (sz && ok) 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 15 ms 45404 KB Output is correct
2 Correct 11 ms 45404 KB Output is correct
3 Correct 10 ms 45660 KB Output is correct
4 Correct 12 ms 45404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 45404 KB Output is correct
2 Correct 11 ms 45404 KB Output is correct
3 Correct 10 ms 45660 KB Output is correct
4 Correct 12 ms 45404 KB Output is correct
5 Correct 10 ms 45464 KB Output is correct
6 Correct 12 ms 45400 KB Output is correct
7 Correct 14 ms 45472 KB Output is correct
8 Correct 15 ms 45404 KB Output is correct
9 Correct 16 ms 45660 KB Output is correct
10 Correct 18 ms 45400 KB Output is correct
11 Correct 10 ms 45220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1035 ms 48360 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 45220 KB Output is correct
2 Correct 123 ms 45736 KB Output is correct
3 Correct 683 ms 47188 KB Output is correct
4 Correct 400 ms 46448 KB Output is correct
5 Correct 414 ms 46584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 45464 KB Output is correct
2 Correct 12 ms 45400 KB Output is correct
3 Correct 14 ms 45472 KB Output is correct
4 Correct 15 ms 45404 KB Output is correct
5 Correct 16 ms 45660 KB Output is correct
6 Correct 18 ms 45400 KB Output is correct
7 Correct 10 ms 45220 KB Output is correct
8 Correct 15 ms 45404 KB Output is correct
9 Correct 11 ms 45404 KB Output is correct
10 Correct 10 ms 45660 KB Output is correct
11 Correct 12 ms 45404 KB Output is correct
12 Execution timed out 1035 ms 48360 KB Time limit exceeded
13 Halted 0 ms 0 KB -