QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#604934#4937. Permutation TransformationNMK#WA 7ms4656kbC++171.6kb2024-10-02 14:39:422024-10-02 14:39:42

Judging History

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

  • [2024-10-02 14:39:42]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:4656kb
  • [2024-10-02 14:39:42]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,cnt;
int a[100005],c[100005];
int c2[100005];
ll mod = 998244353;

map <int,int> p;

void dfs(int x) {
    if(c[x]) return;
    cnt++; c[x] = 1;
    dfs(a[x]);
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie();
    cin >> n;
    for(int i = 1;i <= n;i++) {
        cin >> a[i];
    }
    int mx = 0;
    int ans = 1;
    for(int i = 1;i <= n;i++) {
        if(c[i]) continue;
        cnt = 0;
        dfs(i);
        
        int j,g = 1,idx = 0;
        for(j = 1;j <= n;j++) {
            if(c2[idx]) break;
            
            c2[idx] = j;
            idx = (idx+g)%cnt;
            g = g*2%cnt;
        }
        

        int st = c2[idx]-1;
        int re = j-c2[idx];
        int val = re,cn;
        for(int j = 2;j*j <= val;j++) {
            if(val % j == 0) {
                cn = 0;
                while(val % j == 0) {
                    val /= j;
                    cn++;
                }
                p[j] = max(p[j],cn);
            }
        }
        if(val != 1) {
            p[val] = max(p[val],1);
        }
        mx = max(mx,st);
        
        idx = 0; g = 1;
        for(j = 1;j <= cnt;j++) {
            
            
            c2[idx] = 0;
            idx = (idx+g)%cnt;
            g = g*2%cnt;
        }
        
    }
    for(auto &[x,y] : p) {
        for(int i = 0;i < y;i++) {
            //cout << x << '\n';
            ans = ans*x%mod;
        }
    }
    cout << (ans+mx)%mod;
}

详细

Test #1:

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

input:

5
3 5 1 2 4

output:

3

result:

ok single line: '3'

Test #2:

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

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: 3612kb

input:

1
1

output:

1

result:

ok single line: '1'

Test #4:

score: -100
Wrong Answer
time: 7ms
memory: 4656kb

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:

-899351636

result:

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