#include<iostream>
using namespace std;
int main()
{
int n,sz=0;
cin>>n;
n++;
int autok[n];
for(int i=1;i<n;i++)
{
cin>>autok[i];
}
for(int i=1;i<n;i++)
{
while(autok[i]!=i)
{
swap(autok[i],autok[autok[i]]);
sz++;
}
}
if(sz<2)cout<<"-1 \n";
else cout<<sz<<'\n';
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Runtime error | 1ms | 320 KiB | ||||
2 | Runtime error | 1ms | 320 KiB | ||||
subtask2 | 0/7 | ||||||
3 | Runtime error | 1ms | 320 KiB | ||||
4 | Runtime error | 1ms | 508 KiB | ||||
5 | Time limit exceeded | 2.079s | 320 KiB | ||||
6 | Runtime error | 1ms | 320 KiB | ||||
7 | Runtime error | 1ms | 512 KiB | ||||
8 | Runtime error | 1ms | 320 KiB | ||||
9 | Time limit exceeded | 2.099s | 320 KiB | ||||
10 | Runtime error | 1ms | 320 KiB | ||||
11 | Runtime error | 1ms | 508 KiB | ||||
12 | Time limit exceeded | 2.078s | 320 KiB | ||||
13 | Runtime error | 1ms | 320 KiB | ||||
subtask3 | 0/23 | ||||||
14 | Time limit exceeded | 2.079s | 1268 KiB | ||||
15 | Runtime error | 64ms | 1080 KiB | ||||
16 | Runtime error | 63ms | 1084 KiB | ||||
17 | Runtime error | 68ms | 1080 KiB | ||||
18 | Runtime error | 68ms | 1080 KiB | ||||
19 | Runtime error | 70ms | 1084 KiB | ||||
20 | Time limit exceeded | 2.085s | 1080 KiB | ||||
21 | Runtime error | 54ms | 1160 KiB | ||||
22 | Time limit exceeded | 2.076s | 1080 KiB | ||||
23 | Time limit exceeded | 2.082s | 1080 KiB | ||||
24 | Time limit exceeded | 2.085s | 1080 KiB | ||||
25 | Runtime error | 57ms | 1096 KiB | ||||
subtask4 | 0/21 | ||||||
26 | Time limit exceeded | 2.085s | 1080 KiB | ||||
27 | Time limit exceeded | 2.085s | 1080 KiB | ||||
28 | Time limit exceeded | 2.086s | 1088 KiB | ||||
29 | Time limit exceeded | 2.085s | 940 KiB | ||||
30 | Time limit exceeded | 2.075s | 1080 KiB | ||||
31 | Time limit exceeded | 2.075s | 1016 KiB | ||||
32 | Time limit exceeded | 2.075s | 1080 KiB | ||||
33 | Time limit exceeded | 2.072s | 1152 KiB | ||||
34 | Time limit exceeded | 2.088s | 1084 KiB | ||||
35 | Time limit exceeded | 2.089s | 1080 KiB | ||||
subtask5 | 0/49 | ||||||
36 | Runtime error | 1ms | 508 KiB | ||||
37 | Runtime error | 1ms | 320 KiB | ||||
38 | Runtime error | 1ms | 320 KiB | ||||
39 | Runtime error | 1ms | 508 KiB | ||||
40 | Time limit exceeded | 2.079s | 320 KiB | ||||
41 | Runtime error | 1ms | 320 KiB | ||||
42 | Runtime error | 1ms | 512 KiB | ||||
43 | Runtime error | 1ms | 320 KiB | ||||
44 | Time limit exceeded | 2.099s | 320 KiB | ||||
45 | Runtime error | 1ms | 320 KiB | ||||
46 | Runtime error | 1ms | 508 KiB | ||||
47 | Time limit exceeded | 2.078s | 320 KiB | ||||
48 | Runtime error | 1ms | 320 KiB | ||||
49 | Time limit exceeded | 2.079s | 1268 KiB | ||||
50 | Runtime error | 64ms | 1080 KiB | ||||
51 | Runtime error | 63ms | 1084 KiB | ||||
52 | Runtime error | 68ms | 1080 KiB | ||||
53 | Runtime error | 68ms | 1080 KiB | ||||
54 | Runtime error | 70ms | 1084 KiB | ||||
55 | Time limit exceeded | 2.085s | 1080 KiB | ||||
56 | Runtime error | 54ms | 1160 KiB | ||||
57 | Time limit exceeded | 2.076s | 1080 KiB | ||||
58 | Time limit exceeded | 2.082s | 1080 KiB | ||||
59 | Time limit exceeded | 2.085s | 1080 KiB | ||||
60 | Runtime error | 57ms | 1096 KiB | ||||
61 | Time limit exceeded | 2.085s | 1080 KiB | ||||
62 | Time limit exceeded | 2.085s | 1080 KiB | ||||
63 | Time limit exceeded | 2.086s | 1088 KiB | ||||
64 | Time limit exceeded | 2.085s | 940 KiB | ||||
65 | Time limit exceeded | 2.075s | 1080 KiB | ||||
66 | Time limit exceeded | 2.075s | 1016 KiB | ||||
67 | Time limit exceeded | 2.075s | 1080 KiB | ||||
68 | Time limit exceeded | 2.072s | 1152 KiB | ||||
69 | Time limit exceeded | 2.088s | 1084 KiB | ||||
70 | Time limit exceeded | 2.089s | 1080 KiB | ||||
71 | Runtime error | 61ms | 1080 KiB | ||||
72 | Runtime error | 65ms | 1072 KiB | ||||
73 | Runtime error | 61ms | 1080 KiB | ||||
74 | Runtime error | 71ms | 1080 KiB | ||||
75 | Runtime error | 72ms | 1080 KiB | ||||
76 | Runtime error | 70ms | 1000 KiB | ||||
77 | Runtime error | 70ms | 1080 KiB | ||||
78 | Runtime error | 54ms | 1100 KiB | ||||
79 | Time limit exceeded | 2.085s | 1136 KiB | ||||
80 | Runtime error | 54ms | 1080 KiB | ||||
81 | Runtime error | 54ms | 1080 KiB | ||||
82 | Runtime error | 57ms | 1080 KiB | ||||
83 | Time limit exceeded | 2.085s | 1092 KiB | ||||
84 | Runtime error | 71ms | 1080 KiB |