114882024-10-09 16:16:41MCDaveMagic Wandscpp17Wrong answer 31/100451ms11384 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 << ' ';
        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
1Accepted3ms360 KiB
2Accepted3ms360 KiB
subtask214/14
3Accepted3ms384 KiB
4Accepted3ms504 KiB
5Accepted3ms360 KiB
6Accepted3ms360 KiB
7Accepted2ms360 KiB
8Accepted3ms256 KiB
9Accepted2ms376 KiB
subtask317/17
10Accepted3ms512 KiB
11Accepted3ms488 KiB
12Accepted3ms512 KiB
13Accepted3ms384 KiB
14Accepted3ms360 KiB
15Accepted2ms376 KiB
subtask40/23
16Accepted4ms404 KiB
17Accepted4ms632 KiB
18Accepted4ms416 KiB
19Wrong answer4ms360 KiB
20Wrong answer4ms504 KiB
21Accepted4ms360 KiB
subtask50/46
22Accepted43ms1440 KiB
23Wrong answer90ms2512 KiB
24Accepted224ms5912 KiB
25Accepted451ms11384 KiB
26Accepted444ms11368 KiB
27Accepted442ms11368 KiB
28Accepted442ms11384 KiB
29Accepted433ms10344 KiB
30Accepted446ms11368 KiB