QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#395431 | #7687. Randias Permutation Task | zzuqy# | WA | 1ms | 3624kb | C++14 | 1.4kb | 2024-04-21 14:35:46 | 2024-04-21 14:35:47 |
Judging History
answer
#include <bits/stdc++.h>
#define N 189
#define ull unsigned long long
using namespace std;
int n, m;
int a[N][N];
int tmp[N];
void change(int *a, int *b) {
for (int i = 1; i <= n; i++)
tmp[i] = a[b[i]];
for (int i = 1; i <= n; i++)
a[i] = tmp[i];
}
ull hsh1(int *a) {
ull ans = 0;
for (int i = 1; i <= n; i++)
ans = ans * 1239738 + a[i];
return ans;
}
ull hsh2(int *a) {
ull ans = 0;
for (int i = 1; i <= n; i++)
ans = ans * 10 + a[i];
return ans;
}
int b[N][N];
unordered_set<ull>s;
void dfs(int x, int lstx) {
if (x == m + 1) {
s.insert(hsh1(b[lstx]));
return;
}
dfs(x + 1, lstx);
for (int i = 1; i <= n; i++) {
b[x][i] = a[x][b[lstx][i]];
}
dfs(x + 1, x);
}
unordered_set<ull>p[N];
int calc(int x, int *c) {
for (int i = n; i >= 1; i--) {
b[0][i] = x % 10;
x /= 10;
}
for (int i = 1; i <= n; i++)
b[1][i] = b[0][c[i]];
return hsh2(b[1]);
}
int main() {
cin >> n >> m;
for (int i = 1; i <= m; i++)
for (int j = 1; j <= n; j++)
cin >> a[i][j];
for (int i = 1; i <= n; i++)
b[0][i] = i;
if (m <= 18) {
dfs(1, 0);
cout << s.size() << endl;
} else if (n <= 9) {
p[0].insert(hsh2(b[0]));
for (int i = 1; i <= m; i++) {
for (auto c : p[i - 1])
p[i].insert(calc(c, a[i])), p[i].insert(c);
}
cout << p[m].size() << endl;
} else
assert(0);
return 0;
}
/*
5 4
1 2 3 4 5
5 1 3 4 2
3 4 1 5 2
5 2 4 1 3
2 1
2 1
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3624kb
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: -100
Wrong Answer
time: 1ms
memory: 3556kb
input:
2 1 2 1
output:
2
result:
wrong answer 1st numbers differ - expected: '1', found: '2'