114892024-10-09 16:20:41MCDaveMagic Wandscpp17Accepted 100/100462ms11408 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++)
    {
        while (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 << ' ';
        return 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
subtask214/14
3Accepted3ms360 KiB
4Accepted3ms384 KiB
5Accepted3ms360 KiB
6Accepted3ms360 KiB
7Accepted2ms368 KiB
8Accepted3ms376 KiB
9Accepted2ms512 KiB
subtask317/17
10Accepted3ms364 KiB
11Accepted2ms388 KiB
12Accepted3ms408 KiB
13Accepted3ms296 KiB
14Accepted2ms384 KiB
15Accepted2ms384 KiB
subtask423/23
16Accepted4ms408 KiB
17Accepted4ms504 KiB
18Accepted4ms384 KiB
19Accepted4ms400 KiB
20Accepted4ms504 KiB
21Accepted4ms504 KiB
subtask546/46
22Accepted43ms1512 KiB
23Accepted90ms2488 KiB
24Accepted228ms5676 KiB
25Accepted455ms11328 KiB
26Accepted448ms11368 KiB
27Accepted449ms11368 KiB
28Accepted448ms11408 KiB
29Accepted437ms10348 KiB
30Accepted462ms11284 KiB