QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#209036#4937. Permutation TransformationZiadElGafyWA 6ms4320kbC++201.9kb2023-10-10 04:36:002023-10-10 04:36:00

Judging History

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

  • [2023-10-10 04:36:00]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:4320kb
  • [2023-10-10 04:36:00]
  • 提交

answer

#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

#define el '\n'
#define F first
#define S second

typedef long long ll;
typedef long double ld;
typedef __int128 bigInt;

using namespace std;

const int N = 1e5 + 5, INF = 1e9 + 5, mod = 1e9 + 7, LOG = 21, SQ = 500;

int n, p[N], mx[N];

int solve(int cnt) {
    if (cnt == 1) {
        return 1;
    }

    int cur = 1, ret = 0;

    do {
        cur = (cur * 2) % cnt;
        ret++;
    } while (cur % cnt != 1);

    return ret;
}

void doWork() {
    cin >> n;

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

    vector<bool> vis(n + 1, 0);

    int mxStart = 0;

    for (int i = 1; i <= n; i++) {
        if (vis[i]) {
            continue;
        }

        vis[i] = 1;

        int cnt = 1, cur = i;

        while (!vis[p[cur]]) {
            cnt++;
            cur = p[cur];
            vis[cur] = 1;
        }

        int curStart = 0;

        while (cnt % 2 == 0) {
            curStart++;
            cnt >>= 1;
        }

        mxStart = max(mxStart, curStart);

        int iterations = solve(cnt);

        for (int j = 2; 1LL * j * j <= iterations; j++) {
            int f = 0;
            while (iterations % j == 0) {
                f++;
                iterations /= j;
            }
            mx[j] = max(mx[j], f);
        }

        if (iterations > 1) {
            mx[iterations] = max(mx[iterations], 1);
        }
    }

    int ans = 1;

    for (int i = 2; i <= n; i++) {
        while (mx[i]--) {
            ans = 1LL * ans * i % mod;
        }
    }

    ans = (ans + mxStart) % mod;

    cout << ans << el;
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    int tests = 1;
//    cin >> tests;
    for (int i = 1; i <= tests; i++) {
        doWork();
    }
}

詳細信息

Test #1:

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

input:

5
3 5 1 2 4

output:

3

result:

ok single line: '3'

Test #2:

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

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

input:

1
1

output:

1

result:

ok single line: '1'

Test #4:

score: -100
Wrong Answer
time: 6ms
memory: 4320kb

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:

167174887

result:

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