QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#286488#7687. Randias Permutation Tasketohari#WA 0ms3620kbC++141.8kb2023-12-17 22:45:442023-12-17 22:45:45

Judging History

你现在查看的是最新测评结果

  • [2023-12-17 22:45:45]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3620kb
  • [2023-12-17 22:45:44]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#ifndef LOCAL
#define cerr \
  if (0) cerr
#endif

map<vector<int>, int> dp[185];
int a[185][185];
int n, m;

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifdef LOCAL
#define task "a"
#else
#define task ""
#endif
  if (fopen(task ".inp", "r")) {
    freopen(task ".inp", "r", stdin);
    freopen(task ".out", "w", stdout);
  }
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      cin >> a[i][j];
      // a[i][j]++;
    }
  }
  if (m <= 18) {
    vector<int> p;
    map<vector<int>, int> mp;
    for (int mask = 1; mask < 1 << m; mask++) {
      vector<int> c(n);
      iota(c.begin(), c.end(), 0);
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          if (mask >> j & 1) {
            c[i] = a[j][c[i]];
          }
        }
      }
      ++mp[c];
    }
    cout << mp.size() << "\n";
    // for (auto [v, _] : mp) {
    //   for (int i : v) cerr << i << " ";
    //   cerr << endl;
    // }
    return 0;
  }
  // dp[i] = tap cac hoan vi khi xet i thang hoan vi dau
  vector<int> p(n);
  iota(p.begin(), p.end(), 0);

  // for (int i : p) cerr << i << ",";
  // cerr << endl;
  for (int i = 1; i <= m; i++) {
    dp[i] = dp[i - 1];
    for (auto [v, _] : dp[i - 1]) {
      vector<int> nv = v;
      for (int j = 0; j <= n; j++) {
        nv[j] = a[i][v[j]];
        // if (i == 1) cerr << j << " " << nv[j] << endl;
      }
      dp[i][nv] = 1;
    }
    dp[i][vector<int>(a[i], a[i] + n + 1)] = 1;
  }
  // dp[m][p]--;
  // if (dp[m][p] == 0) dp[m].erase(p);
  // for (auto [v, _] : dp[2]) {
  //   for (int i : v) cerr << i << " ";
  //   cerr << endl;
  // }
  cout << dp[m].size();
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3620kb

input:

5 4
1 2 3 4 5
5 1 3 4 2
3 4 1 5 2
5 2 4 1 3

output:

5

result:

wrong answer 1st numbers differ - expected: '8', found: '5'