#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
static int A[5000];
void solve(int N) {
int diff2[N+2],diff3[N+2],cnt[N+2];
for (int i=1;i<N;i++)
{
if (i<N-1)
diff3[i]=query(i,i+2);
diff2[i]=query(i,i+1);
}
for (int i=1;i<=N;i++)
{
int cur=1;
A[1]=i;
for (int j=2;j<=N;j++)
{
if (j>2 && N>2 && diff3[j-2]!=diff2[j-2]+diff2[j-1])
cur*=(-1);
A[j]=A[j-1]+diff2[j-1]*cur;
}
bool yes=true;
for (int j=1;j<=N;j++)
cnt[j]=0;
for (int j=1;j<=N;j++)
{
if (A[j]<=N && A[j]>=1)
{
if ((A[j]==N && !cnt[1]) || cnt[A[j]])
yes=false;
cnt[A[j]]++;
}
}
for (int j=1;j<=N;j++)
{
if (!cnt[j])
yes=false;
}
if (yes)
{
for (int j=1;j<=N;j++)
answer(j,A[j]);
return;
}
yes=true;
cur=-1;
for (int j=2;j<=N;j++)
{
if (j>2 && N>2 && diff3[j-2]!=diff2[j-2]+diff2[j-1])
cur*=(-1);
A[j]=A[j-1]+diff2[j-1]*cur;
}
for (int j=1;j<=N;j++)
cnt[j]=0;
for (int j=1;j<=N;j++)
{
if (A[j]<=N && A[j]>=1)
{
if ((A[j]==N && !cnt[1]) || cnt[A[j]])
yes=false;
cnt[A[j]]++;
}
}
for (int j=1;j<=N;j++)
{
if (!cnt[j])
yes=false;
}
if (yes)
{
for (int j=1;j<=N;j++)
answer(j,A[j]);
return;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
3 ms |
208 KB |
Output is correct |
5 |
Correct |
3 ms |
208 KB |
Output is correct |
6 |
Correct |
3 ms |
208 KB |
Output is correct |
7 |
Correct |
3 ms |
208 KB |
Output is correct |
8 |
Correct |
2 ms |
208 KB |
Output is correct |
9 |
Correct |
3 ms |
208 KB |
Output is correct |
10 |
Correct |
2 ms |
208 KB |
Output is correct |
11 |
Correct |
3 ms |
208 KB |
Output is correct |
12 |
Correct |
3 ms |
208 KB |
Output is correct |
13 |
Correct |
2 ms |
208 KB |
Output is correct |
14 |
Correct |
2 ms |
208 KB |
Output is correct |
15 |
Correct |
2 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
3 ms |
208 KB |
Output is correct |
5 |
Correct |
3 ms |
208 KB |
Output is correct |
6 |
Correct |
3 ms |
208 KB |
Output is correct |
7 |
Correct |
3 ms |
208 KB |
Output is correct |
8 |
Correct |
2 ms |
208 KB |
Output is correct |
9 |
Correct |
3 ms |
208 KB |
Output is correct |
10 |
Correct |
2 ms |
208 KB |
Output is correct |
11 |
Correct |
3 ms |
208 KB |
Output is correct |
12 |
Correct |
3 ms |
208 KB |
Output is correct |
13 |
Correct |
2 ms |
208 KB |
Output is correct |
14 |
Correct |
2 ms |
208 KB |
Output is correct |
15 |
Correct |
2 ms |
208 KB |
Output is correct |
16 |
Correct |
5 ms |
208 KB |
Output is correct |
17 |
Correct |
13 ms |
208 KB |
Output is correct |
18 |
Correct |
22 ms |
304 KB |
Output is correct |
19 |
Correct |
28 ms |
208 KB |
Output is correct |
20 |
Correct |
28 ms |
208 KB |
Output is correct |
21 |
Correct |
25 ms |
208 KB |
Output is correct |
22 |
Correct |
23 ms |
208 KB |
Output is correct |
23 |
Correct |
21 ms |
208 KB |
Output is correct |
24 |
Correct |
26 ms |
208 KB |
Output is correct |
25 |
Correct |
12 ms |
300 KB |
Output is correct |
26 |
Correct |
25 ms |
300 KB |
Output is correct |
27 |
Correct |
18 ms |
208 KB |
Output is correct |
28 |
Correct |
20 ms |
292 KB |
Output is correct |
29 |
Correct |
26 ms |
208 KB |
Output is correct |
30 |
Correct |
10 ms |
312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
3 ms |
208 KB |
Output is correct |
5 |
Correct |
3 ms |
208 KB |
Output is correct |
6 |
Correct |
3 ms |
208 KB |
Output is correct |
7 |
Correct |
3 ms |
208 KB |
Output is correct |
8 |
Correct |
2 ms |
208 KB |
Output is correct |
9 |
Correct |
3 ms |
208 KB |
Output is correct |
10 |
Correct |
2 ms |
208 KB |
Output is correct |
11 |
Correct |
3 ms |
208 KB |
Output is correct |
12 |
Correct |
3 ms |
208 KB |
Output is correct |
13 |
Correct |
2 ms |
208 KB |
Output is correct |
14 |
Correct |
2 ms |
208 KB |
Output is correct |
15 |
Correct |
2 ms |
208 KB |
Output is correct |
16 |
Correct |
5 ms |
208 KB |
Output is correct |
17 |
Correct |
13 ms |
208 KB |
Output is correct |
18 |
Correct |
22 ms |
304 KB |
Output is correct |
19 |
Correct |
28 ms |
208 KB |
Output is correct |
20 |
Correct |
28 ms |
208 KB |
Output is correct |
21 |
Correct |
25 ms |
208 KB |
Output is correct |
22 |
Correct |
23 ms |
208 KB |
Output is correct |
23 |
Correct |
21 ms |
208 KB |
Output is correct |
24 |
Correct |
26 ms |
208 KB |
Output is correct |
25 |
Correct |
12 ms |
300 KB |
Output is correct |
26 |
Correct |
25 ms |
300 KB |
Output is correct |
27 |
Correct |
18 ms |
208 KB |
Output is correct |
28 |
Correct |
20 ms |
292 KB |
Output is correct |
29 |
Correct |
26 ms |
208 KB |
Output is correct |
30 |
Correct |
10 ms |
312 KB |
Output is correct |
31 |
Correct |
58 ms |
308 KB |
Output is correct |
32 |
Correct |
177 ms |
328 KB |
Output is correct |
33 |
Correct |
196 ms |
344 KB |
Output is correct |
34 |
Correct |
290 ms |
360 KB |
Output is correct |
35 |
Correct |
349 ms |
356 KB |
Output is correct |
36 |
Correct |
116 ms |
340 KB |
Output is correct |
37 |
Correct |
188 ms |
456 KB |
Output is correct |
38 |
Correct |
90 ms |
344 KB |
Output is correct |
39 |
Correct |
113 ms |
360 KB |
Output is correct |
40 |
Correct |
229 ms |
352 KB |
Output is correct |
41 |
Correct |
275 ms |
352 KB |
Output is correct |
42 |
Correct |
94 ms |
336 KB |
Output is correct |
43 |
Correct |
198 ms |
344 KB |
Output is correct |
44 |
Correct |
89 ms |
356 KB |
Output is correct |
45 |
Correct |
174 ms |
340 KB |
Output is correct |
46 |
Correct |
246 ms |
344 KB |
Output is correct |
47 |
Correct |
304 ms |
344 KB |
Output is correct |
48 |
Correct |
95 ms |
352 KB |
Output is correct |
49 |
Correct |
312 ms |
344 KB |
Output is correct |
50 |
Correct |
254 ms |
712 KB |
Output is correct |
51 |
Correct |
223 ms |
472 KB |
Output is correct |
52 |
Correct |
121 ms |
352 KB |
Output is correct |
53 |
Correct |
342 ms |
360 KB |
Output is correct |
54 |
Correct |
331 ms |
460 KB |
Output is correct |
55 |
Correct |
365 ms |
356 KB |
Output is correct |
56 |
Correct |
410 ms |
352 KB |
Output is correct |
57 |
Correct |
342 ms |
352 KB |
Output is correct |
58 |
Correct |
403 ms |
356 KB |
Output is correct |
59 |
Correct |
280 ms |
356 KB |
Output is correct |
60 |
Correct |
262 ms |
352 KB |
Output is correct |