QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#133712#4937. Permutation Transformation4k2kok#WA 9ms5028kbC++201.3kb2023-08-02 13:16:282023-08-02 13:16:30

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 13:16:30]
  • 评测
  • 测评结果:WA
  • 用时:9ms
  • 内存:5028kb
  • [2023-08-02 13:16:28]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mem(a,b) memset((a),(b),sizeof(a))
typedef long long ll;
typedef unsigned long long ull;
#define int long long

const int maxn = 1e5 + 10;
int gcd(int a,int b) {return b?gcd(b,a%b):a;}
int lcm(int a,int b) {return a/gcd(a,b)*b;}
int n, a[maxn], vis[maxn], num[maxn];

void solve() {
    cin >> n;
    int cnt = 0;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for(int i = 1; i <= n; i++) {
        int temp = a[i];
        if(vis[temp]) continue;
        cnt++;
        while(vis[temp] == 0) {
            vis[temp] = 1;
            temp = a[temp];
            num[cnt]++;
        }
    }
    // cout << cnt << '\n';
    // for(int i = 1; i <= cnt; i++) {
    //     cout << num[i] << " ";
    // }
    sort(num + 1, num + 1 + cnt);
    if(num[cnt] >= 5) {
        int ans = 1;
        for(int i = 1; i <= cnt; i++) {
            if(num[i] <= 4) continue;
            ans = lcm(ans, num[i] - 1);
        }
        cout << ans << '\n';
    } else {
        cout << num[cnt] << '\n';
    }
}

signed main(){
    io;
    int T = 1;
    //cin >> T;
    while(T--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
3 5 1 2 4

output:

3

result:

ok single line: '3'

Test #2:

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

input:

8
7 5 1 6 8 2 3 4

output:

4

result:

ok single line: '4'

Test #3:

score: 0
Accepted
time: 2ms
memory: 3588kb

input:

1
1

output:

1

result:

ok single line: '1'

Test #4:

score: -100
Wrong Answer
time: 9ms
memory: 5028kb

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:

-6430470326718197888

result:

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