QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#835528#4937. Permutation Transformationmrkiencf#WA 4ms6124kbC++141.5kb2024-12-28 12:35:002024-12-28 12:35:02

Judging History

This is the latest submission verdict.

  • [2024-12-28 12:35:02]
  • Judged
  • Verdict: WA
  • Time: 4ms
  • Memory: 6124kb
  • [2024-12-28 12:35:00]
  • Submitted

answer

/// fptu UWR
#include <bits/stdc++.h>
#define int long long

using namespace std;

const int O = 1e5 + 5;
const int mod = 998244353;

int n, dem, d[O], p[O], dd[O], Max[O];

int exp(int a, int x){
    int res = 1;
    for (; x; x >>= 1, a = 1ll * a * a % mod) if (x & 1) res = 1ll * res * a % mod;
    return res;
}

void dfs(int u){
    dd[u] = 1;
    if (!dd[p[u]]) dfs(p[u]);
    dem += 1;
}

main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    if (fopen("input.in", "r")){
        freopen("input.in", "r", stdin);
        freopen("output.out", "w", stdout);
    }

    cin >> n;
    for (int i = 1; i <= n; ++ i){
        cin >> p[i];
    }

    vector<int> res;
    for (int i = 1; i <= n; ++ i){
        if (!dd[i]){
            dem = 0;
            dfs(i);
            if (dem > 1) res.push_back(dem - 1);
        }
    }

    d[1] = 1;
    for (int i = 2; i < O; ++ i){
        if (!d[i]){
            d[i] = i;
            for (int j = i * i; j < O; j += i) d[j] = i;
        }
    }

    for (int i : res){
        int x = i;
        while (x != 1){
            int z = d[x], cur = 0;
            while (x % z == 0){
                x /= z;
                cur += 1;
            }
            Max[z] = max(Max[z], cur);
        }
    }

    int ans = 1;
    for (int i = 2; i < O; ++ i){
        ans = 1ll * ans * exp(i, Max[i]) % mod;
    }

    for (int i : res) ans = (ans + (i == 1)) % mod;

    cout << ans;

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
3 5 1 2 4

output:

3

result:

ok single line: '3'

Test #2:

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

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

input:

1
1

output:

1

result:

ok single line: '1'

Test #4:

score: -100
Wrong Answer
time: 4ms
memory: 6120kb

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:

338374676

result:

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