QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#236787#7687. Randias Permutation Taskucup-team180#WA 1431ms60420kbC++171.7kb2023-11-04 10:43:262023-11-04 10:43:26

Judging History

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

  • [2023-11-04 10:43:26]
  • 评测
  • 测评结果:WA
  • 用时:1431ms
  • 内存:60420kb
  • [2023-11-04 10:43:26]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, m;
  cin >> n >> m;
  vector<vector<int>> A(m, vector<int>(n));
  for (int i = 0; i < m; i++){
    for (int j = 0; j < n; j++){
      cin >> A[i][j];
      A[i][j]--;
    }
  }
  if (n <= 20){
    vector<vector<int>> ans;
    for (int i = 1; i < (1 << m); i++){
      vector<int> p(n);
      for (int j = 0; j < n; j++){
        p[j] = j;
      }
      for (int j = 0; j < m; j++){
        if ((i >> j & 1) == 1){
          vector<int> q(n);
          for (int k = 0; k < n; k++){
            q[k] = p[A[j][k]];
          }
          p = q;
        }
      }
      ans.push_back(p);
    }
    sort(ans.begin(), ans.end());
    cout << unique(ans.begin(), ans.end()) - ans.begin() << endl;
  } else {
    vector<int> p(n);
    for (int i = 0; i < n; i++){
      p[i] = i;
    }
    int F = 1;
    for (int i = 1; i <= n; i++){
      F *= i;
    }
    vector<vector<int>> P;
    for (int i = 0; i < F + 1; i++){
      P.push_back(p);
      next_permutation(p.begin(), p.end());
    }
    vector<vector<bool>> dp(m + 1, vector<bool>(F + 1, false));
    dp[0][F] = true;
    for (int i = 0; i < m; i++){
      for (int j = 0; j <= F; j++){
        if (dp[i][j]){
          dp[i + 1][j] = true;
          vector<int> q(n);
          for (int k = 0; k < n; k++){
            q[k] = P[j][A[i][k]];
          }
          int idx = lower_bound(P.begin(), P.end() - 1, q) - P.begin();
          dp[i + 1][idx] = true;
        }
      }
    }
    int ans = 0;
    for (int i = 0; i < F; i++){
      if (dp[m][i]){
        ans++;
      }
    }
    cout << ans << endl;
  }
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3584kb

input:

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

output:

8

result:

ok 1 number(s): "8"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3620kb

input:

2 1
2 1

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Accepted
time: 1431ms
memory: 60420kb

input:

1 180
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3536kb

input:

180 1
52 71 167 89 165 102 119 125 9 128 180 24 48 172 108 22 164 28 159 111 30 91 67 51 136 97 126 133 177 65 115 157 114 11 171 178 23 127 163 103 99 18 56 94 176 77 44 1 124 74 61 87 4 40 63 92 169 84 146 6 88 55 152 49 10 90 43 174 70 50 69 154 73 147 110 20 82 59 112 12 64 143 16 138 5 170 155 ...

output:

0

result:

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