#include "xylophone.h"
#include "bits/stdc++.h"
using namespace std;
static int A[5001];
static bool Used[5001];
void solve(int N) {
int l = 1, r = N - 1;
while (l < r) {
int mid = (l + r + 1) >> 1;
if (query(mid, N) == N - 1) {
l = mid;
} else {
r = mid - 1;
}
}
A[l] = 1;
A[l + 1] = query(l, l + 1) + 1;
Used[A[l]] = Used[A[l + 1]] = true;
for (int i = l + 2; i <= N; ++i) {
int diff = query(i - 1, i);
bool pre = A[i - 1] - diff > 1 && !Used[A[i - 1] - diff];
bool aft = A[i - 1] + diff <= N && !Used[A[i - 1] + diff];
if (pre && aft) {
int diff2 = query(i - 2, i);
if (A[i - 2] < A[i - 1]) {
if (diff2 == A[i - 1] - A[i - 2] + diff) {
A[i] = A[i - 1] + diff;
} else {
A[i] = A[i - 1] - diff;
}
} else {
if (diff2 == A[i - 2] - A[i - 1] + diff) {
A[i] = A[i - 1] - diff;
} else {
A[i] = A[i - 1] + diff;
}
}
} else if (pre) {
A[i] = A[i - 1] - diff;
} else {
A[i] = A[i - 1] + diff;
}
Used[A[i]] = true;
}
if (l > 1) {
A[l - 1] = query(l - 1, l) + 1;
Used[A[l - 1]] = true;
for (int i = l - 2; i > 0; --i) {
int diff = query(i, i + 1);
bool pre = A[i + 1] - diff > 1 && !Used[A[i + 1] - diff];
bool aft = A[i + 1] + diff <= N && !Used[A[i + 1] + diff];
if (pre && aft) {
int diff2 = query(i, i + 2);
if (A[i + 2] < A[i + 1]) {
if (diff2 == A[i + 1] - A[i + 2] + diff) {
A[i] = A[i + 1] + diff;
} else {
A[i] = A[i + 1] - diff;
}
} else {
if (diff2 == A[i + 2] - A[i + 1] + diff) {
A[i] = A[i + 1] - diff;
} else {
A[i] = A[i + 1] + diff;
}
}
} else if (pre) {
A[i] = A[i + 1] - diff;
} else {
A[i] = A[i + 1] + diff;
}
Used[A[i]] = true;
}
}
for (int i = 1; i <= N; ++i) {
cout << A[i] << ' ';
}
cout << '\n';
for (int i = 1; i <= N; ++i) {
answer(i, A[i]);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |