#include <bits/stdc++.h>
#include "xylophone.h"
using namespace std;
const int maxn = 5010;
int a[maxn];
bool done[maxn];
void solve(int n)
{
int l = 1;
int r = n;
while (l <= r) {
int mid = (l + r) / 2;
if (query(mid, n) == n - 1) l = mid + 1;
else r = mid - 1;
}
l--;
// cout << l << endl;
answer(l, 1);
a[l] = 1;
done[1] = true;
for (int i = l - 1; i >= 1; i--) {
int x = query(i, i + 1);
int ans = -1;
if (a[i + 1] - x <= 0 || done[a[i + 1] - x]) ans = a[i + 1] + x;
if (a[i + 1] + x > n || done[a[i + 1] + x]) ans = a[i + 1] - x;
if (ans == -1) {
if (abs(a[i + 1] + x - a[i + 2]) != query(i, i + 2)) ans = a[i + 1] - x;
else ans = a[i + 1] + x;
}
a[i] = ans;
done[ans] = true;
answer(i, a[i]);
}
for (int i = l + 1; i <= n; i++) {
int x = query(i - 1, i);
int ans = -1;
if (a[i - 1] - x <= 0 || done[a[i - 1] - x]) ans = a[i - 1] + x;
if (a[i - 1] + x > n || done[a[i - 1] + x]) ans = a[i - 1] - x;
if (ans == -1) {
if (abs(a[i - 1] + x - a[i - 2]) != query(i - 2, i)) ans = a[i - 1] - x;
else ans = a[i - 1] + x;
}
a[i] = ans;
done[ans] = true;
answer(i, a[i]);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
296 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 |
296 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 |
296 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 |
- |