QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#244076#7687. Randias Permutation Taskucup-team2432#WA 1ms3440kbC++201.9kb2023-11-08 20:57:012023-11-08 20:57:01

Judging History

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

  • [2023-11-08 20:57:01]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3440kb
  • [2023-11-08 20:57:01]
  • 提交

answer

#include<bits/stdc++.h>

using LL = long long;
const LL inf = 1e9;
const LL P = 1e9+7;
LL K = 1;

LL hash(const std::vector<int> &vec) {
	LL res = 0,unit = 1;
	int n = vec.size() - 1;
	for (int i = 0; i < n; ++i) {
		res = (res + unit * vec[i]) % P;
		unit = unit * K % P;
	}
	return res;
}

void solve() {

	std::mt19937 rnd(std::random_device{}());
	K = rnd() % P;
	K = std::max(K,10ll);

	int n,m;std::cin >> n >> m;
	std::vector pmt(m,std::vector<int>(n+1));
	for (int i = 0; i < m; ++i) {
		for (int j = 0; j < n; ++j) {
			std::cin >> pmt[i][j];
		}
	}
	std::map<LL,int> mp;
	std::priority_queue<std::pair<int,std::vector<int>>,std::vector<std::pair<int,std::vector<int>>>,std::greater<>> q;
	for (int i = 0; i < m; ++i) {
		LL ouo = rnd() % P;
		pmt[i][n] = ouo;
		q.emplace(i+1,pmt[i]);
	}
	while (!q.empty()) {
		auto [point,vec] = q.top();q.pop();
		LL hsh = hash(vec);
		if (!mp.count(hsh)) {
//			std::cout << point << '\n';
			mp[hsh] = vec.back();
		} else {
//			std::cout << point << " " << hsh << ' ' << mp[hsh] << " " << vec.back() << '\n';
			if (mp[hsh] != vec.back()) {
				continue;
			}
		}
		if (point == m) continue;
		q.emplace(point+1,vec);
//		for (int i = 0; i < n; ++i) {
//			std::cout << vec[i] << " ";
//		}
//		std::cout << '\n';
		for (int i = 0; i < n; ++i) {
			vec[i] = pmt[0][vec[i] - 1];
//			std::cout << vec[i] << " ";
		}
		vec[n] = rnd() % P;
//		std::cout << '\n';
//		std::cout << '\n';
		q.emplace(point+1,vec);
	}
	std::cout << mp.size() % P;
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

//    clock_t st = clock();
//    std::cout << std::fixed << std::setprecision(12);

//    freopen("test.in", "r", stdin);
//    freopen("test.out", "w", stdout);

	int T = 1;
//	std::cin >> T;
	while (T --) {
		solve();
	}

//    std::cout << (double)(clock()-st)/CLOCKS_PER_SEC;

	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3440kb

input:

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

output:

4

result:

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