114872024-10-09 16:14:30MCDaveMagic Wandscpp17Wrong answer 17/100504ms18308 KiB
#include <iostream>
#include <vector>
#include <math.h>

using namespace std;

int gcd(int larger, int smaller)
{
    while (true)
    {
        if (larger < smaller) swap(larger, smaller);
        int m = larger % smaller;
        if (m == 0) return smaller;
        larger = m;
    }
}

int main()
{
    int i, n, temp1, x=0, lnko;
    cin >> n;
    vector<int> vec(n), avec(n);
    vector<bool> bvec(n);

    for (i = 0; i < n; i++)
    {
        cin >> temp1;
        vec[i] = --temp1;
        avec[i] = abs(temp1 - i);
    }

    for (i = 0; i < n; i++)
    {
        if (vec[i] != i)
        {
            swap(vec[i], vec[vec[i]]);
            x++;
        }
    }

    i = 0;
    while (i < n && avec[i] == 0) i++;
    if (i == n) for (i = 0; i < n; i++) cout << 0;
    lnko = avec[i];

    for (i++; i < n; i++)
    {
        if (avec[i] == 0) continue;
        lnko = gcd(avec[i], lnko);
    }

    for (i = 1; i <= n; i++)
    {
        if (lnko%i==0)
        {
            cout << x << ' ';
        }
        else
        {
            cout << -1 << ' ';
        }
    }
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted2ms360 KiB
2Accepted3ms360 KiB
subtask20/14
3Accepted3ms532 KiB
4Accepted3ms492 KiB
5Accepted3ms528 KiB
6Wrong answer3ms400 KiB
7Accepted2ms376 KiB
8Accepted2ms376 KiB
9Wrong answer3ms632 KiB
subtask317/17
10Accepted3ms504 KiB
11Accepted3ms548 KiB
12Accepted2ms436 KiB
13Accepted3ms504 KiB
14Accepted3ms504 KiB
15Accepted3ms360 KiB
subtask40/23
16Accepted4ms376 KiB
17Accepted4ms496 KiB
18Accepted4ms760 KiB
19Wrong answer4ms504 KiB
20Wrong answer4ms488 KiB
21Accepted4ms488 KiB
subtask50/46
22Accepted43ms2064 KiB
23Wrong answer90ms3784 KiB
24Accepted225ms9140 KiB
25Accepted451ms17928 KiB
26Accepted444ms18108 KiB
27Accepted444ms18308 KiB
28Accepted442ms17988 KiB
29Wrong answer504ms17948 KiB
30Accepted449ms18024 KiB