QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#780991#4937. Permutation Transformationstd_abs#WA 6ms4368kbC++201.5kb2024-11-25 14:18:542024-11-25 14:19:00

Judging History

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

  • [2024-11-25 14:19:00]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:4368kb
  • [2024-11-25 14:18:54]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) ((int)a.size())
const int mod = 998244353, N = 100007;

int add(int a, int b) {
	a += b;
	if (a >= mod) a -= mod;
	return a;
}

int mul(int a, int b) {
	return 1ll * a * b % mod;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	int n;
	cin >> n;
	vector <int> p(n);
	for (int i = 0; i < n; ++i) {
		cin >> p[i], --p[i];
	}
	vector <int> cyc;
	vector <bool> vis(n, false);
	for (int i = 0; i < n; ++i) if (!vis[i]) {
		int cnt = 0;
		for (int x = i; !vis[x]; x = p[x]) {
			vis[x] = true, cnt++;
		}
		cyc.pb(cnt);
	}
	int ans = 1, more = 0;
	while (true) {
		bool even = false;
		for (int x : cyc) {
			if (x % 2 == 0) even = true;
		}
		if (!even) {
			break;
		}
		more++;
		vector <int> ncyc;
		for (int x : cyc) {
			if (x % 2 == 0) ncyc.pb(x / 2);
			else ncyc.pb(x);
		}
		cyc = ncyc;
	}

	vector <int> cnt(n + 1), lp(n + 1);
	for (int i = 2; i <= n; ++i) if (!lp[i]) {
		for (int j = i; j <= n; j += i) if (!lp[j]) {
			lp[j] = i;
		}
	}

	for (int x : cyc) {
		int cur = x - 1;
		while (cur > 1) {
			int p = lp[cur];
			int c = 0;
			while (cur % p == 0) {
				cur /= p;
				c++;
			}
			cnt[p] = max(cnt[p], c);
		}
	}

	for (int i = 2; i <= n; ++i) {
		for (int j = 0; j < cnt[i]; ++j) {
			ans = mul(ans, i);
		}
	}

	cout << add(ans, more) << '\n';
}

詳細信息

Test #1:

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

input:

5
3 5 1 2 4

output:

3

result:

ok single line: '3'

Test #2:

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

input:

8
7 5 1 6 8 2 3 4

output:

4

result:

ok single line: '4'

Test #3:

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

input:

1
1

output:

1

result:

ok single line: '1'

Test #4:

score: -100
Wrong Answer
time: 6ms
memory: 4368kb

input:

100000
20864 34918 58550 1465 75674 30743 27235 88900 47488 50029 46054 84871 20330 72228 16506 44561 92519 97750 82891 60324 90508 39290 24663 38077 90189 30671 95476 64027 70888 90749 22566 8525 33675 16635 23392 97636 35788 89625 41966 78051 94034 15407 26545 83799 2233 10873 56946 71566 19045 44...

output:

32660679

result:

wrong answer 1st lines differ - expected: '216333199', found: '32660679'