#include <bits/stdc++.h>
//#include "grader.cpp"
#include "xylophone.h"
using namespace std;
int Ar[5050];
bool mark[5050];
void solve(int N) {
int idx;
int l = 1, r = N;
while (l < r) {
int mid = (l+r)/2;
if (query(mid+1, N) == N-1) l = mid+1;
else r = mid;
}
idx = l;
Ar[idx] = 1;
mark[idx] = 1;
for (int i = idx+1; i <= N; ++i) {
int dif = query(i-1, i), cur;
if (Ar[i-1]+dif>N || mark[Ar[i-1]+dif]) {
cur = Ar[i-1]-dif;
}
else if (Ar[i-1]-dif<1 || mark[Ar[i-1]-dif]) {
cur = Ar[i-1]+dif;
}
else {
int dif2 = query(i-2, i);
if (Ar[i-2] > Ar[i-1]+dif){
if (Ar[i-2] - Ar[i-1] == dif2) cur = Ar[i-1]+dif;
}
if (Ar[i-2] < Ar[i-1]+dif) {
if (Ar[i-1]+dif - min(Ar[i-2], Ar[i-1]) == dif2) cur = Ar[i-1]+dif;
}
if (Ar[i-2] > Ar[i-1]-dif){
if (max(Ar[i-2], Ar[i-1]) - Ar[i-1]+dif == dif2) cur = Ar[i-1]-dif;
}
if (Ar[i-2] < Ar[i-1]-dif) {
if (Ar[i-1] - Ar[i-2] == dif2) cur = Ar[i-1]-dif;
}
}
Ar[i] = cur;
mark[cur] = 1;
}
for (int i = idx-1; i >= 1; --i) {
int dif = query(i, i+1), cur;
if (Ar[i+1]+dif>N || mark[Ar[i+1]+dif]) {
cur = Ar[i+1]-dif;
}
else if (Ar[i+1]-dif<1 || mark[Ar[i+1]-dif]) {
cur = Ar[i+1]+dif;
}
else {
int dif2 = query(i-2, i);
if (Ar[i+2] > Ar[i+1]+dif){
if (Ar[i+2] - Ar[i+1] == dif2) cur = Ar[i+1]+dif;
}
if (Ar[i+2] < Ar[i+1]+dif) {
if (Ar[i+1]+dif - min(Ar[i+2], Ar[i+1]) == dif2) cur = Ar[i+1]+dif;
}
if (Ar[i+2] > Ar[i+1]-dif){
if (max(Ar[i+2], Ar[i+1]) - Ar[i+1]+dif == dif2) cur = Ar[i+1]-dif;
}
if (Ar[i+2] < Ar[i+1]-dif) {
if (Ar[i+1] - Ar[i+2] == dif2) cur = Ar[i+1]-dif;
}
}
Ar[i] = cur;
mark[cur] = 1;
}
for (int i = 1; i <= N; ++i) {
answer(i, Ar[i]);
}
}
Compilation message
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:71:15: warning: 'cur' may be used uninitialized in this function [-Wmaybe-uninitialized]
71 | Ar[i] = cur;
| ~~~~~~^~~~~
xylophone.cpp:44:15: warning: 'cur' may be used uninitialized in this function [-Wmaybe-uninitialized]
44 | Ar[i] = cur;
| ~~~~~~^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Incorrect |
1 ms |
208 KB |
Wrong Answer [7] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Incorrect |
1 ms |
208 KB |
Wrong Answer [7] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Incorrect |
1 ms |
208 KB |
Wrong Answer [7] |
4 |
Halted |
0 ms |
0 KB |
- |