#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
int dif[5001][5001],c[5001],st,ans[5001];
void solve(int n) {
for (int i=1; i<n; ++i) dif[i][i+1]=query(i,i+1);
for (int i=1; i<n-1; ++i) dif[i][i+2]=query(i,i+2);
//first let c[1]>0
c[1]=dif[1][2];
for (int i=2; i<n; ++i) {
c[i]=dif[i][i+1];
if (dif[i-1][i]+dif[i][i+1]==dif[i-1][i+1]) {
if (c[i-1]<0) c[i]=-c[i];
} else {
if (c[i-1]>0) c[i]=-c[i];
}
}
for (int i=1; i<n; ++i) {
int sum=0;
bool have=false;
for (int j=i; j<n; ++j) {
sum+=c[j];
if (abs(sum)==n-1) {
have=true;
st=i;
ans[st]=1;
if (sum==1-n) for (int i=1; i<n; ++i) c[i]=-c[i];
break;
}
}
if (have) break;
}
for (int i=st+1; i<=n; ++i) ans[i]=ans[i-1]+c[i-1];
for (int i=st-1; i>=1; --i) ans[i]=ans[i+1]-c[i];
for (int i=1; i<=n; ++i) answer(i,ans[i]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
2 ms |
464 KB |
Output is correct |
4 |
Correct |
2 ms |
696 KB |
Output is correct |
5 |
Correct |
4 ms |
592 KB |
Output is correct |
6 |
Correct |
3 ms |
592 KB |
Output is correct |
7 |
Correct |
3 ms |
592 KB |
Output is correct |
8 |
Correct |
3 ms |
592 KB |
Output is correct |
9 |
Correct |
3 ms |
592 KB |
Output is correct |
10 |
Correct |
2 ms |
592 KB |
Output is correct |
11 |
Correct |
2 ms |
688 KB |
Output is correct |
12 |
Correct |
2 ms |
708 KB |
Output is correct |
13 |
Correct |
3 ms |
696 KB |
Output is correct |
14 |
Correct |
4 ms |
632 KB |
Output is correct |
15 |
Correct |
2 ms |
692 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
2 ms |
464 KB |
Output is correct |
4 |
Correct |
2 ms |
696 KB |
Output is correct |
5 |
Correct |
4 ms |
592 KB |
Output is correct |
6 |
Correct |
3 ms |
592 KB |
Output is correct |
7 |
Correct |
3 ms |
592 KB |
Output is correct |
8 |
Correct |
3 ms |
592 KB |
Output is correct |
9 |
Correct |
3 ms |
592 KB |
Output is correct |
10 |
Correct |
2 ms |
592 KB |
Output is correct |
11 |
Correct |
2 ms |
688 KB |
Output is correct |
12 |
Correct |
2 ms |
708 KB |
Output is correct |
13 |
Correct |
3 ms |
696 KB |
Output is correct |
14 |
Correct |
4 ms |
632 KB |
Output is correct |
15 |
Correct |
2 ms |
692 KB |
Output is correct |
16 |
Correct |
5 ms |
1220 KB |
Output is correct |
17 |
Correct |
11 ms |
2172 KB |
Output is correct |
18 |
Correct |
16 ms |
3608 KB |
Output is correct |
19 |
Correct |
18 ms |
4304 KB |
Output is correct |
20 |
Correct |
24 ms |
4328 KB |
Output is correct |
21 |
Correct |
24 ms |
4320 KB |
Output is correct |
22 |
Correct |
23 ms |
4248 KB |
Output is correct |
23 |
Correct |
21 ms |
4324 KB |
Output is correct |
24 |
Correct |
17 ms |
4236 KB |
Output is correct |
25 |
Correct |
29 ms |
4296 KB |
Output is correct |
26 |
Correct |
26 ms |
4332 KB |
Output is correct |
27 |
Correct |
22 ms |
4268 KB |
Output is correct |
28 |
Correct |
21 ms |
4360 KB |
Output is correct |
29 |
Correct |
18 ms |
4348 KB |
Output is correct |
30 |
Correct |
20 ms |
4304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
2 ms |
464 KB |
Output is correct |
4 |
Correct |
2 ms |
696 KB |
Output is correct |
5 |
Correct |
4 ms |
592 KB |
Output is correct |
6 |
Correct |
3 ms |
592 KB |
Output is correct |
7 |
Correct |
3 ms |
592 KB |
Output is correct |
8 |
Correct |
3 ms |
592 KB |
Output is correct |
9 |
Correct |
3 ms |
592 KB |
Output is correct |
10 |
Correct |
2 ms |
592 KB |
Output is correct |
11 |
Correct |
2 ms |
688 KB |
Output is correct |
12 |
Correct |
2 ms |
708 KB |
Output is correct |
13 |
Correct |
3 ms |
696 KB |
Output is correct |
14 |
Correct |
4 ms |
632 KB |
Output is correct |
15 |
Correct |
2 ms |
692 KB |
Output is correct |
16 |
Correct |
5 ms |
1220 KB |
Output is correct |
17 |
Correct |
11 ms |
2172 KB |
Output is correct |
18 |
Correct |
16 ms |
3608 KB |
Output is correct |
19 |
Correct |
18 ms |
4304 KB |
Output is correct |
20 |
Correct |
24 ms |
4328 KB |
Output is correct |
21 |
Correct |
24 ms |
4320 KB |
Output is correct |
22 |
Correct |
23 ms |
4248 KB |
Output is correct |
23 |
Correct |
21 ms |
4324 KB |
Output is correct |
24 |
Correct |
17 ms |
4236 KB |
Output is correct |
25 |
Correct |
29 ms |
4296 KB |
Output is correct |
26 |
Correct |
26 ms |
4332 KB |
Output is correct |
27 |
Correct |
22 ms |
4268 KB |
Output is correct |
28 |
Correct |
21 ms |
4360 KB |
Output is correct |
29 |
Correct |
18 ms |
4348 KB |
Output is correct |
30 |
Correct |
20 ms |
4304 KB |
Output is correct |
31 |
Correct |
43 ms |
9048 KB |
Output is correct |
32 |
Correct |
36 ms |
12768 KB |
Output is correct |
33 |
Correct |
96 ms |
17964 KB |
Output is correct |
34 |
Correct |
125 ms |
20476 KB |
Output is correct |
35 |
Correct |
58 ms |
20528 KB |
Output is correct |
36 |
Correct |
94 ms |
20508 KB |
Output is correct |
37 |
Correct |
67 ms |
20524 KB |
Output is correct |
38 |
Correct |
55 ms |
20480 KB |
Output is correct |
39 |
Correct |
118 ms |
20580 KB |
Output is correct |
40 |
Correct |
137 ms |
20556 KB |
Output is correct |
41 |
Correct |
102 ms |
20552 KB |
Output is correct |
42 |
Correct |
113 ms |
20476 KB |
Output is correct |
43 |
Correct |
132 ms |
20548 KB |
Output is correct |
44 |
Correct |
115 ms |
20500 KB |
Output is correct |
45 |
Correct |
99 ms |
20528 KB |
Output is correct |
46 |
Correct |
100 ms |
20564 KB |
Output is correct |
47 |
Correct |
110 ms |
20516 KB |
Output is correct |
48 |
Correct |
106 ms |
20488 KB |
Output is correct |
49 |
Correct |
157 ms |
20528 KB |
Output is correct |
50 |
Correct |
109 ms |
20508 KB |
Output is correct |
51 |
Correct |
116 ms |
20468 KB |
Output is correct |
52 |
Correct |
153 ms |
20476 KB |
Output is correct |
53 |
Correct |
108 ms |
20508 KB |
Output is correct |
54 |
Correct |
126 ms |
20512 KB |
Output is correct |
55 |
Correct |
132 ms |
20500 KB |
Output is correct |
56 |
Correct |
127 ms |
20508 KB |
Output is correct |
57 |
Correct |
101 ms |
20576 KB |
Output is correct |
58 |
Correct |
107 ms |
20480 KB |
Output is correct |
59 |
Correct |
69 ms |
20476 KB |
Output is correct |
60 |
Correct |
123 ms |
20492 KB |
Output is correct |