#include "xylophone.h"
#include <set>
using namespace std;
void solve(int n){
int a[n+1],b[n+1],c[n+1];
for (int i=0;i<=n;i++){
a[i]=0;
b[i]=0;
c[i]=0;
}
for (int i=1;i+1<=n;i++)
a[i]=query(i,i+1);
for (int i=1;i+2<=n;i++){
int val=query(i,i+2);
b[i+1]=(a[i]+a[i+1]==val?1:-1);
}
int d=1,mx=0,mn=0;
set <int> s;
s.insert(0);
for (int i=2;i<=n;i++){
c[i]=c[i-1]+d*a[i-1];
d*=b[i];
s.insert(c[i]);
mx=max(mx,c[i]);
mn=min(mn,c[i]);
}
if (s.size()==n&&mx-mn+1==n){
int ch=0;
for (int i=1;i<=n;i++){
c[i]-=mn-1;
if (c[i]==1)
ch=1;
if (c[i]==n)
if (!ch)
break;
}
if (ch){
for (int i=1;i<=n;i++)
answer(i,c[i]);
return;
}
}
c[1]=0;
d=-1;
mn=0;
for (int i=2;i<=n;i++){
c[i]=c[i-1]+d*a[i-1];
d*=b[i];
mn=min(mn,c[i]);
}
for (int i=1;i<=n;i++)
answer(i,c[i]-mn+1);
}
Compilation message
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:27:17: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
27 | if (s.size()==n&&mx-mn+1==n){
| ~~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
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 |
2 ms |
208 KB |
Output is correct |
5 |
Correct |
2 ms |
208 KB |
Output is correct |
6 |
Correct |
2 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
288 KB |
Output is correct |
8 |
Correct |
2 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
2 ms |
284 KB |
Output is correct |
12 |
Correct |
2 ms |
284 KB |
Output is correct |
13 |
Correct |
2 ms |
208 KB |
Output is correct |
14 |
Correct |
2 ms |
288 KB |
Output is correct |
15 |
Correct |
3 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
2 ms |
208 KB |
Output is correct |
5 |
Correct |
2 ms |
208 KB |
Output is correct |
6 |
Correct |
2 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
288 KB |
Output is correct |
8 |
Correct |
2 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
2 ms |
284 KB |
Output is correct |
12 |
Correct |
2 ms |
284 KB |
Output is correct |
13 |
Correct |
2 ms |
208 KB |
Output is correct |
14 |
Correct |
2 ms |
288 KB |
Output is correct |
15 |
Correct |
3 ms |
208 KB |
Output is correct |
16 |
Correct |
4 ms |
208 KB |
Output is correct |
17 |
Correct |
10 ms |
284 KB |
Output is correct |
18 |
Correct |
13 ms |
208 KB |
Output is correct |
19 |
Correct |
15 ms |
292 KB |
Output is correct |
20 |
Correct |
16 ms |
284 KB |
Output is correct |
21 |
Correct |
16 ms |
272 KB |
Output is correct |
22 |
Correct |
15 ms |
288 KB |
Output is correct |
23 |
Correct |
18 ms |
276 KB |
Output is correct |
24 |
Correct |
16 ms |
288 KB |
Output is correct |
25 |
Correct |
16 ms |
288 KB |
Output is correct |
26 |
Correct |
8 ms |
284 KB |
Output is correct |
27 |
Correct |
20 ms |
292 KB |
Output is correct |
28 |
Correct |
18 ms |
288 KB |
Output is correct |
29 |
Correct |
16 ms |
292 KB |
Output is correct |
30 |
Correct |
15 ms |
288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
2 ms |
208 KB |
Output is correct |
5 |
Correct |
2 ms |
208 KB |
Output is correct |
6 |
Correct |
2 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
288 KB |
Output is correct |
8 |
Correct |
2 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
2 ms |
284 KB |
Output is correct |
12 |
Correct |
2 ms |
284 KB |
Output is correct |
13 |
Correct |
2 ms |
208 KB |
Output is correct |
14 |
Correct |
2 ms |
288 KB |
Output is correct |
15 |
Correct |
3 ms |
208 KB |
Output is correct |
16 |
Correct |
4 ms |
208 KB |
Output is correct |
17 |
Correct |
10 ms |
284 KB |
Output is correct |
18 |
Correct |
13 ms |
208 KB |
Output is correct |
19 |
Correct |
15 ms |
292 KB |
Output is correct |
20 |
Correct |
16 ms |
284 KB |
Output is correct |
21 |
Correct |
16 ms |
272 KB |
Output is correct |
22 |
Correct |
15 ms |
288 KB |
Output is correct |
23 |
Correct |
18 ms |
276 KB |
Output is correct |
24 |
Correct |
16 ms |
288 KB |
Output is correct |
25 |
Correct |
16 ms |
288 KB |
Output is correct |
26 |
Correct |
8 ms |
284 KB |
Output is correct |
27 |
Correct |
20 ms |
292 KB |
Output is correct |
28 |
Correct |
18 ms |
288 KB |
Output is correct |
29 |
Correct |
16 ms |
292 KB |
Output is correct |
30 |
Correct |
15 ms |
288 KB |
Output is correct |
31 |
Correct |
42 ms |
292 KB |
Output is correct |
32 |
Correct |
60 ms |
432 KB |
Output is correct |
33 |
Correct |
80 ms |
444 KB |
Output is correct |
34 |
Correct |
88 ms |
596 KB |
Output is correct |
35 |
Correct |
88 ms |
580 KB |
Output is correct |
36 |
Correct |
105 ms |
592 KB |
Output is correct |
37 |
Correct |
73 ms |
584 KB |
Output is correct |
38 |
Correct |
70 ms |
580 KB |
Output is correct |
39 |
Correct |
97 ms |
464 KB |
Output is correct |
40 |
Correct |
83 ms |
584 KB |
Output is correct |
41 |
Correct |
75 ms |
580 KB |
Output is correct |
42 |
Correct |
47 ms |
580 KB |
Output is correct |
43 |
Correct |
82 ms |
580 KB |
Output is correct |
44 |
Correct |
60 ms |
580 KB |
Output is correct |
45 |
Correct |
88 ms |
584 KB |
Output is correct |
46 |
Correct |
81 ms |
580 KB |
Output is correct |
47 |
Correct |
87 ms |
584 KB |
Output is correct |
48 |
Correct |
94 ms |
580 KB |
Output is correct |
49 |
Correct |
96 ms |
576 KB |
Output is correct |
50 |
Correct |
71 ms |
588 KB |
Output is correct |
51 |
Correct |
80 ms |
580 KB |
Output is correct |
52 |
Correct |
77 ms |
592 KB |
Output is correct |
53 |
Correct |
74 ms |
580 KB |
Output is correct |
54 |
Correct |
59 ms |
576 KB |
Output is correct |
55 |
Correct |
99 ms |
584 KB |
Output is correct |
56 |
Correct |
97 ms |
580 KB |
Output is correct |
57 |
Correct |
50 ms |
580 KB |
Output is correct |
58 |
Correct |
52 ms |
580 KB |
Output is correct |
59 |
Correct |
98 ms |
576 KB |
Output is correct |
60 |
Correct |
99 ms |
580 KB |
Output is correct |