QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#133580 | #4937. Permutation Transformation | Rd_rainydays# | WA | 2ms | 4152kb | C++17 | 1.5kb | 2023-08-02 11:29:47 | 2023-08-02 11:29:50 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
#define REP(i,a,b) for(int i=(a),i##_end_=(b);i<i##_end_;++i)
static const int M=100003;
static const int Mod=998244353;
int n,A[M];
int P[M],Rk[M],q;
int Pri[M],pt;
int Vis[M],Time[M],Ans[M];
int main(){
REP(i,2,M){
if(!Vis[i]){
Pri[pt++]=i;
for(int j=i+i;j<M;j+=i)
Vis[j]=1;
}
}
memset(Vis,0,sizeof(Vis));
scanf("%d",&n);
REP(i,1,n+1)scanf("%d",&A[i]);
int mxt=0;
REP(i,1,n+1)if(!Vis[i]){
int u=i,q=0;
Vis[i]=1;
do{
P[q++]=u;
u=A[u];
Vis[u]=1;
}while(u!=i);
//REP(j,0,q)cout<<P[j]<<' ';cout<<endl;
Time[P[0]]=1;
int st=1,p=0;
while(1){
int nt=(p+st)%q;
st++;
//cout<<p<<','<<A[P[p]]<<','<<Rk[A[P[p]]]<<endl;
//cout<<A[P[p]]<<"->"<<A[P[nt]]<<endl;
if(Time[P[nt]]){
int lp=st-Time[P[nt]];
//cout<<"loop:"<<lp<<endl;
mxt=max(mxt,Time[P[nt]]-1);
REP(tt,0,pt){
int pri=Pri[tt];
if(pri*pri>lp)break;
int ts=0;
while(!(lp%pri))ts++,lp/=pri;
Ans[pri]=max(Ans[pri],ts);
}
Ans[lp]=max(Ans[lp],1);
break;
}
p=nt;
Time[P[p]]=st;
}
//cout<<i<<','<<mxt<<endl;
}
int ss=1;
REP(i,2,n+1)
while(Ans[i]--)ss=1ll*ss*i%Mod;
printf("%d\n",(mxt+ss)%Mod);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 4096kb
input:
5 3 5 1 2 4
output:
3
result:
ok single line: '3'
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 4152kb
input:
8 7 5 1 6 8 2 3 4
output:
3
result:
wrong answer 1st lines differ - expected: '4', found: '3'