QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#395452#7687. Randias Permutation Taskzzuqy#WA 0ms3876kbC++141.4kb2024-04-21 14:48:462024-04-21 14:48:46

Judging History

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

  • [2024-04-21 14:48:46]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3876kb
  • [2024-04-21 14:48:46]
  • 提交

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] = b[lstx][a[x][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] = c[b[0][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: 0ms
memory: 3876kb

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: 0ms
memory: 3844kb

input:

2 1
2 1

output:

2

result:

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