QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#133580#4937. Permutation TransformationRd_rainydays#WA 2ms4152kbC++171.5kb2023-08-02 11:29:472023-08-02 11:29:50

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 11:29:50]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:4152kb
  • [2023-08-02 11:29:47]
  • 提交

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;
}

详细

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'