#include "xylophone.h"
#include<bits/stdc++.h>
using namespace std;
const int N = 5e3;
int res[N + 1];
void solve(int n) {
int l = 1,r = n;
int pos;
while(l < r) {
int mid = (l + r)/2;
if(query(mid,n) == n - 1) {
l = mid + 1;
pos = mid;
} else {
r = mid;
}
}
res[pos] = 1;
for(int i = pos - 1;i >= 1;i--) {
int w = query(i,i + 1);
if(res[i + 1] + w > n) {
res[i] = res[i + 1] - w;
continue;
}
if(res[i + 1] <= w) {
res[i] = res[i + 1] + w;
continue;
}
vector<int> st = {res[i + 1],res[i + 2]};
sort(st.begin(),st.end());
int asd = query(i,i + 2);
if(asd == st[1] - st[0]) {
res[i] = st[1] - w;
} else {
if(asd == w) {
res[i] = st[1] - w;
} else {
res[i] = st[1] + w;
}
}
}
for(int i = pos + 1;i <= n;i++) {
int w = query(i - 1,i);
if(res[i - 1] <= w) {
res[i] = res[i - 1] + w;
continue;
}
if(res[i - 1] + w > n) {
res[i] = res[i - 1] - w;
continue;
}
vector<int> st = {res[i - 1],res[i - 2]};
sort(st.begin(),st.end());
int asd = query(i - 2,i);
if(asd == st[1] - st[0]) {
res[i] = st[1] - w;
} else {
if(asd == w) {
res[i] = st[1] - w;
} else {
res[i] = st[1] + w;
}
}
}
for(int i = 1;i <= n;i++) {
answer(i,res[i]);
}
return;
}
Compilation message
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:11:6: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
11 | int pos;
| ^~~
# |
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 |
Incorrect |
1 ms |
208 KB |
Wrong Answer [4] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
Incorrect |
1 ms |
208 KB |
Wrong Answer [4] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
Incorrect |
1 ms |
208 KB |
Wrong Answer [4] |
4 |
Halted |
0 ms |
0 KB |
- |