#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
int n;
int niz[5005];
int simuliraj(int a, int b, int c){
return max(max(a,b), c) - min(min(a,b), c);
}
bool imam[5005];
void solve(int N){
n = N;
int poz1 = 0;
int l = 1;
int r = n;
while(l < r){
int mid = (l + r + 1) / 2;
int pom = query(mid, n);
if(pom == n - 1){
l = mid;
}
else
r = mid - 1;
}
poz1 = l;
//cout << poz1 << endl;
/*for(int i=n; i>=1; i--){
if(query(i,n) == n-1){
poz1 = i;
break;
}
}*/
niz[poz1] = 1;
if(poz1>1){
niz[poz1 - 1] = 1 + query(poz1 - 1, poz1);
}
niz[poz1 + 1] = 1 + query(poz1, poz1 + 1);
imam[1] = 1;
for(int i=poz1 - 2; i >= 1; i--){
int val1 = query(i,i+1);
int prvi = niz[i + 1] - val1;
int drugi = niz[i + 1] + val1;
if(prvi <= 0 || drugi > n || imam[prvi] || imam[drugi]){
if(prvi <= 0 || imam[prvi]){niz[i] = drugi; imam[drugi] = 1;}
else {niz[i] = prvi; imam[prvi] = 1;}
continue;
}
int val2 = query(i,i+2);
int tmp1 = simuliraj(niz[i + 1], niz[i + 2], prvi);
int tmp2 = simuliraj(niz[i + 1], niz[i + 2], drugi);
if(tmp1 == val2){niz[i] = prvi;imam[prvi] = 1;}
else {niz[i] = drugi;imam[drugi] = 1;}
}
for(int i=poz1+2; i<=n; i++){
int val1 = query(i-1,i);
int prvi = niz[i - 1] - val1;
int drugi = niz[i - 1] + val1;
if(prvi <= 0 || drugi > n || imam[prvi] || imam[drugi]){
if(prvi <= 0 || imam[prvi]){niz[i] = drugi; imam[drugi] = 1;}
else {niz[i] = prvi; imam[prvi] = 1;}
continue;
}
int val2 = query(i-2,i);
int tmp1 = simuliraj(niz[i - 1], niz[i - 2], prvi);
int tmp2 = simuliraj(niz[i - 1], niz[i - 2], drugi);
if(tmp1 == val2){niz[i] = prvi;imam[prvi] = 1;}
else {niz[i] = drugi;imam[drugi] = 1;}
}
for(int i=1; i<=n; i++)answer(i, niz[i]);
}
Compilation message
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:53:13: warning: unused variable 'tmp2' [-Wunused-variable]
int tmp2 = simuliraj(niz[i + 1], niz[i + 2], drugi);
^~~~
xylophone.cpp:68:13: warning: unused variable 'tmp2' [-Wunused-variable]
int tmp2 = simuliraj(niz[i - 1], niz[i - 2], drugi);
^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
248 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
248 KB |
Output is correct |
5 |
Correct |
3 ms |
248 KB |
Output is correct |
6 |
Correct |
3 ms |
248 KB |
Output is correct |
7 |
Correct |
3 ms |
248 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
248 KB |
Output is correct |
10 |
Correct |
3 ms |
248 KB |
Output is correct |
11 |
Correct |
3 ms |
320 KB |
Output is correct |
12 |
Correct |
3 ms |
412 KB |
Output is correct |
13 |
Correct |
4 ms |
248 KB |
Output is correct |
14 |
Correct |
3 ms |
248 KB |
Output is correct |
15 |
Correct |
4 ms |
252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
248 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
248 KB |
Output is correct |
5 |
Correct |
3 ms |
248 KB |
Output is correct |
6 |
Correct |
3 ms |
248 KB |
Output is correct |
7 |
Correct |
3 ms |
248 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
248 KB |
Output is correct |
10 |
Correct |
3 ms |
248 KB |
Output is correct |
11 |
Correct |
3 ms |
320 KB |
Output is correct |
12 |
Correct |
3 ms |
412 KB |
Output is correct |
13 |
Correct |
4 ms |
248 KB |
Output is correct |
14 |
Correct |
3 ms |
248 KB |
Output is correct |
15 |
Correct |
4 ms |
252 KB |
Output is correct |
16 |
Correct |
6 ms |
248 KB |
Output is correct |
17 |
Correct |
9 ms |
376 KB |
Output is correct |
18 |
Correct |
12 ms |
296 KB |
Output is correct |
19 |
Correct |
16 ms |
248 KB |
Output is correct |
20 |
Correct |
9 ms |
400 KB |
Output is correct |
21 |
Correct |
18 ms |
412 KB |
Output is correct |
22 |
Correct |
16 ms |
376 KB |
Output is correct |
23 |
Correct |
15 ms |
248 KB |
Output is correct |
24 |
Correct |
9 ms |
316 KB |
Output is correct |
25 |
Correct |
15 ms |
376 KB |
Output is correct |
26 |
Correct |
13 ms |
416 KB |
Output is correct |
27 |
Correct |
18 ms |
376 KB |
Output is correct |
28 |
Correct |
10 ms |
376 KB |
Output is correct |
29 |
Correct |
19 ms |
248 KB |
Output is correct |
30 |
Correct |
9 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
248 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
248 KB |
Output is correct |
5 |
Correct |
3 ms |
248 KB |
Output is correct |
6 |
Correct |
3 ms |
248 KB |
Output is correct |
7 |
Correct |
3 ms |
248 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
248 KB |
Output is correct |
10 |
Correct |
3 ms |
248 KB |
Output is correct |
11 |
Correct |
3 ms |
320 KB |
Output is correct |
12 |
Correct |
3 ms |
412 KB |
Output is correct |
13 |
Correct |
4 ms |
248 KB |
Output is correct |
14 |
Correct |
3 ms |
248 KB |
Output is correct |
15 |
Correct |
4 ms |
252 KB |
Output is correct |
16 |
Correct |
6 ms |
248 KB |
Output is correct |
17 |
Correct |
9 ms |
376 KB |
Output is correct |
18 |
Correct |
12 ms |
296 KB |
Output is correct |
19 |
Correct |
16 ms |
248 KB |
Output is correct |
20 |
Correct |
9 ms |
400 KB |
Output is correct |
21 |
Correct |
18 ms |
412 KB |
Output is correct |
22 |
Correct |
16 ms |
376 KB |
Output is correct |
23 |
Correct |
15 ms |
248 KB |
Output is correct |
24 |
Correct |
9 ms |
316 KB |
Output is correct |
25 |
Correct |
15 ms |
376 KB |
Output is correct |
26 |
Correct |
13 ms |
416 KB |
Output is correct |
27 |
Correct |
18 ms |
376 KB |
Output is correct |
28 |
Correct |
10 ms |
376 KB |
Output is correct |
29 |
Correct |
19 ms |
248 KB |
Output is correct |
30 |
Correct |
9 ms |
320 KB |
Output is correct |
31 |
Correct |
22 ms |
324 KB |
Output is correct |
32 |
Correct |
32 ms |
328 KB |
Output is correct |
33 |
Correct |
61 ms |
248 KB |
Output is correct |
34 |
Correct |
71 ms |
424 KB |
Output is correct |
35 |
Correct |
53 ms |
420 KB |
Output is correct |
36 |
Correct |
58 ms |
252 KB |
Output is correct |
37 |
Correct |
62 ms |
504 KB |
Output is correct |
38 |
Correct |
57 ms |
424 KB |
Output is correct |
39 |
Correct |
78 ms |
248 KB |
Output is correct |
40 |
Correct |
66 ms |
332 KB |
Output is correct |
41 |
Correct |
50 ms |
332 KB |
Output is correct |
42 |
Correct |
43 ms |
444 KB |
Output is correct |
43 |
Correct |
59 ms |
344 KB |
Output is correct |
44 |
Correct |
50 ms |
248 KB |
Output is correct |
45 |
Correct |
75 ms |
384 KB |
Output is correct |
46 |
Correct |
76 ms |
460 KB |
Output is correct |
47 |
Correct |
76 ms |
412 KB |
Output is correct |
48 |
Correct |
76 ms |
376 KB |
Output is correct |
49 |
Correct |
75 ms |
332 KB |
Output is correct |
50 |
Correct |
53 ms |
336 KB |
Output is correct |
51 |
Correct |
76 ms |
436 KB |
Output is correct |
52 |
Correct |
60 ms |
344 KB |
Output is correct |
53 |
Correct |
63 ms |
344 KB |
Output is correct |
54 |
Correct |
55 ms |
344 KB |
Output is correct |
55 |
Correct |
62 ms |
376 KB |
Output is correct |
56 |
Correct |
66 ms |
340 KB |
Output is correct |
57 |
Correct |
78 ms |
248 KB |
Output is correct |
58 |
Correct |
67 ms |
376 KB |
Output is correct |
59 |
Correct |
73 ms |
248 KB |
Output is correct |
60 |
Correct |
68 ms |
376 KB |
Output is correct |