11488 | 2024-10-09 16:16:41 | MCDave | Magic Wands | cpp17 | Wrong answer 31/100 | 451ms | 11384 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 << ' ';
}
}
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 360 KiB | ||||
2 | Accepted | 3ms | 360 KiB | ||||
subtask2 | 14/14 | ||||||
3 | Accepted | 3ms | 384 KiB | ||||
4 | Accepted | 3ms | 504 KiB | ||||
5 | Accepted | 3ms | 360 KiB | ||||
6 | Accepted | 3ms | 360 KiB | ||||
7 | Accepted | 2ms | 360 KiB | ||||
8 | Accepted | 3ms | 256 KiB | ||||
9 | Accepted | 2ms | 376 KiB | ||||
subtask3 | 17/17 | ||||||
10 | Accepted | 3ms | 512 KiB | ||||
11 | Accepted | 3ms | 488 KiB | ||||
12 | Accepted | 3ms | 512 KiB | ||||
13 | Accepted | 3ms | 384 KiB | ||||
14 | Accepted | 3ms | 360 KiB | ||||
15 | Accepted | 2ms | 376 KiB | ||||
subtask4 | 0/23 | ||||||
16 | Accepted | 4ms | 404 KiB | ||||
17 | Accepted | 4ms | 632 KiB | ||||
18 | Accepted | 4ms | 416 KiB | ||||
19 | Wrong answer | 4ms | 360 KiB | ||||
20 | Wrong answer | 4ms | 504 KiB | ||||
21 | Accepted | 4ms | 360 KiB | ||||
subtask5 | 0/46 | ||||||
22 | Accepted | 43ms | 1440 KiB | ||||
23 | Wrong answer | 90ms | 2512 KiB | ||||
24 | Accepted | 224ms | 5912 KiB | ||||
25 | Accepted | 451ms | 11384 KiB | ||||
26 | Accepted | 444ms | 11368 KiB | ||||
27 | Accepted | 442ms | 11368 KiB | ||||
28 | Accepted | 442ms | 11384 KiB | ||||
29 | Accepted | 433ms | 10344 KiB | ||||
30 | Accepted | 446ms | 11368 KiB |