#include "xylophone.h"
#include <algorithm>
#define qry query
using namespace std;
int n;
bool col[5050];
int a[5050];
int d(int a, int b, int c)
{
return max(a, max(b, c)) - min(a, min(b, c));
}
void solve(int N) {
n = N;
int l = 1, r = n - 1, i1 = n - 1;
while (l <= r)
{
int mid = (l + r) / 2;
if (qry(mid, n) == n - 1) i1 = mid, l = mid + 1;
else r = mid - 1;
}
a[i1] = 1;
//printf("%d\n", i1);
for (int i = i1 - 1; i > 0; i--)
{
int sm = qry(i, i + 1);
if (a[i + 1] - sm < 1 || col[a[i + 1] - sm]) a[i] = a[i + 1] + sm;
else if (a[i + 1] + sm > n || col[a[i + 1] + sm]) a[i] = a[i + 1] - sm;
else
{
int sm1 = qry(i, i + 2);
if (d(a[i + 1], a[i + 2], a[i] + sm) == sm1) a[i] = a[i + 1] + sm;
else a[i] = a[i + 1] - sm;
}
col[a[i]] = 1;
}
for (int i = i1 + 1; i <= n; i++)
{
int sm = qry(i - 1, i);
if (a[i - 1] - sm < 1 || col[a[i - 1] - sm]) a[i] = a[i - 1] + sm;
else if (a[i - 1] + sm > n || col[a[i - 1] + sm]) a[i] = a[i - 1] - sm;
else
{
int sm1 = qry(i - 2, i);
if (d(a[i - 1], a[i - 2], a[i] + sm) == sm1) a[i] = a[i - 1] + sm;
else a[i] = a[i - 1] - sm;
}
col[a[i]] = 1;
}
for (int i = 1; i <= n; i++) answer(i, a[i]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Incorrect |
1 ms |
364 KB |
Wrong Answer [7] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Incorrect |
1 ms |
364 KB |
Wrong Answer [7] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Incorrect |
1 ms |
364 KB |
Wrong Answer [7] |
4 |
Halted |
0 ms |
0 KB |
- |