#include "xylophone.h"
#include<bits/stdc++.h>
using namespace std;
#define PB push_back
#define F first
#define S second
int arr[5050];
map<pair<int,int>,int> mp;
void solve(int N)
{
arr[1]=0;
arr[2]=mp[{1,2}]=query(1,2);
for(int i=3;i<=N;i++)
{
int a1=mp[{i-2,i-1}];
int a2=mp[{i-1,i}]=query(i-1,i);
int a3=mp[{i-2,i}]=query(i-2,i);
if(a1+a2==a3)
{
if(arr[i-2]<arr[i-1])
arr[i]=arr[i-1]+a2;
else
arr[i]=arr[i-1]-a2;
}
else if(a1==a3)
{
if(arr[i-2]<arr[i-1])
arr[i]=arr[i-1]-a2;
else
arr[i]=arr[i-1]+a2;
}
else if(a2==a3)
{
if(arr[i-2]<arr[i-1])
arr[i]=arr[i-1]-a2;
else
arr[i]=arr[i-1]+a2;
}
}
int mn=1e9;
for(int i=1;i<=N;i++)
mn=min(mn,arr[i]);
for(int i=1;i<=N;i++)
arr[i] = arr[i] - mn + 1;
int idx_mn,idx_mx;
for(int i=1;i<=N;i++)
{
if(arr[i]==1)idx_mn=i;
if(arr[i]==N)idx_mx=i;
}
if(idx_mx<idx_mn)
for(int i=1;i<=N;i++)
arr[i] = N - arr[i] + 1;
for(int i=1;i<=N;i++)
answer(i,arr[i]);
return ;
}
Compilation message
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:58:2: warning: 'idx_mx' may be used uninitialized in this function [-Wmaybe-uninitialized]
58 | if(idx_mx<idx_mn)
| ^~
xylophone.cpp:58:2: warning: 'idx_mn' may be used uninitialized in this function [-Wmaybe-uninitialized]
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
2 ms |
208 KB |
Output is correct |
5 |
Correct |
2 ms |
308 KB |
Output is correct |
6 |
Correct |
2 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
2 ms |
308 KB |
Output is correct |
9 |
Correct |
2 ms |
304 KB |
Output is correct |
10 |
Correct |
2 ms |
208 KB |
Output is correct |
11 |
Correct |
3 ms |
296 KB |
Output is correct |
12 |
Correct |
4 ms |
304 KB |
Output is correct |
13 |
Correct |
2 ms |
300 KB |
Output is correct |
14 |
Correct |
3 ms |
208 KB |
Output is correct |
15 |
Correct |
2 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
2 ms |
208 KB |
Output is correct |
5 |
Correct |
2 ms |
308 KB |
Output is correct |
6 |
Correct |
2 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
2 ms |
308 KB |
Output is correct |
9 |
Correct |
2 ms |
304 KB |
Output is correct |
10 |
Correct |
2 ms |
208 KB |
Output is correct |
11 |
Correct |
3 ms |
296 KB |
Output is correct |
12 |
Correct |
4 ms |
304 KB |
Output is correct |
13 |
Correct |
2 ms |
300 KB |
Output is correct |
14 |
Correct |
3 ms |
208 KB |
Output is correct |
15 |
Correct |
2 ms |
208 KB |
Output is correct |
16 |
Correct |
7 ms |
320 KB |
Output is correct |
17 |
Correct |
13 ms |
320 KB |
Output is correct |
18 |
Correct |
20 ms |
336 KB |
Output is correct |
19 |
Correct |
18 ms |
368 KB |
Output is correct |
20 |
Correct |
16 ms |
336 KB |
Output is correct |
21 |
Correct |
18 ms |
344 KB |
Output is correct |
22 |
Correct |
17 ms |
304 KB |
Output is correct |
23 |
Correct |
18 ms |
396 KB |
Output is correct |
24 |
Correct |
22 ms |
336 KB |
Output is correct |
25 |
Correct |
19 ms |
332 KB |
Output is correct |
26 |
Correct |
13 ms |
428 KB |
Output is correct |
27 |
Correct |
17 ms |
488 KB |
Output is correct |
28 |
Correct |
16 ms |
336 KB |
Output is correct |
29 |
Correct |
19 ms |
316 KB |
Output is correct |
30 |
Correct |
23 ms |
404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
300 KB |
Output is correct |
4 |
Correct |
2 ms |
208 KB |
Output is correct |
5 |
Correct |
2 ms |
308 KB |
Output is correct |
6 |
Correct |
2 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
2 ms |
308 KB |
Output is correct |
9 |
Correct |
2 ms |
304 KB |
Output is correct |
10 |
Correct |
2 ms |
208 KB |
Output is correct |
11 |
Correct |
3 ms |
296 KB |
Output is correct |
12 |
Correct |
4 ms |
304 KB |
Output is correct |
13 |
Correct |
2 ms |
300 KB |
Output is correct |
14 |
Correct |
3 ms |
208 KB |
Output is correct |
15 |
Correct |
2 ms |
208 KB |
Output is correct |
16 |
Correct |
7 ms |
320 KB |
Output is correct |
17 |
Correct |
13 ms |
320 KB |
Output is correct |
18 |
Correct |
20 ms |
336 KB |
Output is correct |
19 |
Correct |
18 ms |
368 KB |
Output is correct |
20 |
Correct |
16 ms |
336 KB |
Output is correct |
21 |
Correct |
18 ms |
344 KB |
Output is correct |
22 |
Correct |
17 ms |
304 KB |
Output is correct |
23 |
Correct |
18 ms |
396 KB |
Output is correct |
24 |
Correct |
22 ms |
336 KB |
Output is correct |
25 |
Correct |
19 ms |
332 KB |
Output is correct |
26 |
Correct |
13 ms |
428 KB |
Output is correct |
27 |
Correct |
17 ms |
488 KB |
Output is correct |
28 |
Correct |
16 ms |
336 KB |
Output is correct |
29 |
Correct |
19 ms |
316 KB |
Output is correct |
30 |
Correct |
23 ms |
404 KB |
Output is correct |
31 |
Correct |
37 ms |
544 KB |
Output is correct |
32 |
Correct |
64 ms |
680 KB |
Output is correct |
33 |
Correct |
79 ms |
844 KB |
Output is correct |
34 |
Correct |
74 ms |
984 KB |
Output is correct |
35 |
Correct |
90 ms |
928 KB |
Output is correct |
36 |
Correct |
90 ms |
924 KB |
Output is correct |
37 |
Correct |
66 ms |
908 KB |
Output is correct |
38 |
Correct |
45 ms |
916 KB |
Output is correct |
39 |
Correct |
84 ms |
852 KB |
Output is correct |
40 |
Correct |
57 ms |
976 KB |
Output is correct |
41 |
Correct |
66 ms |
964 KB |
Output is correct |
42 |
Correct |
86 ms |
864 KB |
Output is correct |
43 |
Correct |
82 ms |
1020 KB |
Output is correct |
44 |
Correct |
91 ms |
932 KB |
Output is correct |
45 |
Correct |
54 ms |
896 KB |
Output is correct |
46 |
Correct |
90 ms |
840 KB |
Output is correct |
47 |
Correct |
68 ms |
1032 KB |
Output is correct |
48 |
Correct |
86 ms |
860 KB |
Output is correct |
49 |
Correct |
77 ms |
884 KB |
Output is correct |
50 |
Correct |
80 ms |
932 KB |
Output is correct |
51 |
Correct |
90 ms |
920 KB |
Output is correct |
52 |
Correct |
87 ms |
948 KB |
Output is correct |
53 |
Correct |
101 ms |
944 KB |
Output is correct |
54 |
Correct |
78 ms |
900 KB |
Output is correct |
55 |
Correct |
87 ms |
900 KB |
Output is correct |
56 |
Correct |
104 ms |
1004 KB |
Output is correct |
57 |
Correct |
87 ms |
832 KB |
Output is correct |
58 |
Correct |
81 ms |
932 KB |
Output is correct |
59 |
Correct |
87 ms |
996 KB |
Output is correct |
60 |
Correct |
93 ms |
852 KB |
Output is correct |