11489 | 2024-10-09 16:20:41 | MCDave | Magic Wands | cpp17 | Accepted 100/100 | 462ms | 11408 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 << ' ';
}
}
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 2ms | 360 KiB | ||||
2 | Accepted | 3ms | 360 KiB | ||||
subtask2 | 14/14 | ||||||
3 | Accepted | 3ms | 360 KiB | ||||
4 | Accepted | 3ms | 384 KiB | ||||
5 | Accepted | 3ms | 360 KiB | ||||
6 | Accepted | 3ms | 360 KiB | ||||
7 | Accepted | 2ms | 368 KiB | ||||
8 | Accepted | 3ms | 376 KiB | ||||
9 | Accepted | 2ms | 512 KiB | ||||
subtask3 | 17/17 | ||||||
10 | Accepted | 3ms | 364 KiB | ||||
11 | Accepted | 2ms | 388 KiB | ||||
12 | Accepted | 3ms | 408 KiB | ||||
13 | Accepted | 3ms | 296 KiB | ||||
14 | Accepted | 2ms | 384 KiB | ||||
15 | Accepted | 2ms | 384 KiB | ||||
subtask4 | 23/23 | ||||||
16 | Accepted | 4ms | 408 KiB | ||||
17 | Accepted | 4ms | 504 KiB | ||||
18 | Accepted | 4ms | 384 KiB | ||||
19 | Accepted | 4ms | 400 KiB | ||||
20 | Accepted | 4ms | 504 KiB | ||||
21 | Accepted | 4ms | 504 KiB | ||||
subtask5 | 46/46 | ||||||
22 | Accepted | 43ms | 1512 KiB | ||||
23 | Accepted | 90ms | 2488 KiB | ||||
24 | Accepted | 228ms | 5676 KiB | ||||
25 | Accepted | 455ms | 11328 KiB | ||||
26 | Accepted | 448ms | 11368 KiB | ||||
27 | Accepted | 449ms | 11368 KiB | ||||
28 | Accepted | 448ms | 11408 KiB | ||||
29 | Accepted | 437ms | 10348 KiB | ||||
30 | Accepted | 462ms | 11284 KiB |