QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#133561#4937. Permutation TransformationVengeful_Spirit#WA 1ms3896kbC++201.0kb2023-08-02 11:10:192023-08-02 11:10:22

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:10:22]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3896kb
  • [2023-08-02 11:10:19]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
#define int long long
const int mo=998244353;
int qpow(int a,int b){
  int res=1;
  for(;b;b>>=1,a=a*a%mo){
    if(b&1){
      res=res*a%mo;
    }
  }
  return res;
}
int vis[N],c[N],a[N];
void dfs(int x,int &cnt){
  vis[x]=1;
  cnt++;
  if(!vis[a[x]])
  dfs(a[x],cnt);
}
mt19937 rnd(0);
signed main(){
  int n;
  scanf("%lld",&n);
  for(int i=1;i<=n;i++){
    a[i]=i;
  }
  shuffle(a+1,a+1+n,rnd);
  /*
  for(int i=1;i<=n;i++){
    scanf("%d",&a[i]);
  }
  */
  int cnt=0;
  for(int i=1;i<=n;i++){
    if(!vis[i])dfs(i,c[++cnt]);
  }
  int ans=0,gc=-1,mul=1;
  for(int i=1;i<=cnt;i++){
    int res=0;
    while(c[i]%2==0){
      c[i]/=2;
      res++;
    }
    ans=max(ans,res);
  //  cout<<c[i]<<endl;
    if(c[i]!=1){
      if(gc==-1)gc=mul=c[i]-1;
      else {gc=gcd(gc,c[i]-1);
	mul=mul*(c[i]-1)%mo;
	mul=mul*qpow(gc,mo-2)%mo;
      }
    //  cout<<gc<<' '<<mul<<endl;
    }
  }
  ans+=mul;
  printf("%lld\n",ans);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3896kb

input:

5
3 5 1 2 4

output:

3

result:

ok single line: '3'

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3760kb

input:

8
7 5 1 6 8 2 3 4

output:

3

result:

wrong answer 1st lines differ - expected: '4', found: '3'