QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#133509#4937. Permutation Transformationwhsyhyyh#WA 5ms4780kbC++141.4kb2023-08-02 10:23:252023-08-02 10:23:30

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-02 10:23:30]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:4780kb
  • [2023-08-02 10:23:25]
  • 提交

answer

#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define N 100010
#define LL long long
#define mod 998244353
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define drep(i,r,l) for(int i=r;i>=l;i--)
using namespace std;
int rd() {
	int res=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') f*=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') res=(res<<1)+(res<<3)+(ch^48),ch=getchar();
	return res*f;
}
int n,a[N],b[N],m;
bool vis[N];int pri[N],tot,pre[N],mx[N];
void Deal_first() {
	rep(i,2,n) {
		if(!vis[i]) pri[++tot]=i,pre[i]=tot;
		for(int j=1;j<=tot&&i*pri[j]<=n;j++) {
			vis[i*pri[j]]=1,pre[i*pri[j]]=j;
			if(i%pri[j]==0) break;
		}
	}
}
void dfs(int x,int cnt) {
	vis[x]=1;
	if(!vis[a[x]]) dfs(a[x],cnt+1);
	else b[++m]=cnt;
}
int main() {
	n=rd();
	Deal_first();
	rep(i,1,n) a[i]=rd(),vis[i]=0;
	rep(i,1,n) if(!vis[i]) dfs(i,1);
	
	LL ans=0;
	rep(i,1,m) {
		if(b[i]&1) {
			b[i]--;
			while(b[i]>1) {
				int tmp=pre[b[i]],cnt=0;
				while(b[i]%pri[tmp]==0) b[i]/=pri[tmp],cnt++;
				mx[tmp]=max(mx[tmp],cnt);
			}
		}
		else ans=max(ans,1ll*b[i]-1);
	}
	LL res=1;
	rep(i,1,tot) {
		while(mx[i]--) res=res*pri[i]%mod;
	}
	printf("%lld",(res+ans)%mod);
	return 0;
}

详细

Test #1:

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

input:

5
3 5 1 2 4

output:

3

result:

ok single line: '3'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3572kb

input:

8
7 5 1 6 8 2 3 4

output:

4

result:

ok single line: '4'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3892kb

input:

1
1

output:

1

result:

ok single line: '1'

Test #4:

score: -100
Wrong Answer
time: 5ms
memory: 4780kb

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:

426270779

result:

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