# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
145451 | faremy | Xylophone (JOI18_xylophone) | C++14 | 147 ms | 508 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "xylophone.h"
static int A[5000];
const int MAXN = 5e3;
int diff[MAXN];
int direction[MAXN];
int relAns[MAXN];
void solve(int N)
{
for (int i = 1; i < N; i++)
diff[i - 1] = query(i, i + 1);
direction[0] = 1;
for (int i = 2; i < N; i++)
{
direction[i - 1] = direction[i - 2];
if (query(i - 1, i + 1) != diff[i - 2] + diff[i - 1])
direction[i - 1] *= -1;
}
int posMin = 0, posMax = 0;
for (int i = 1; i < N; i++)
{
relAns[i] = relAns[i - 1] + diff[i - 1] * direction[i - 1];
if (relAns[i] < relAns[posMin])
posMin = i;
if (relAns[i] > relAns[posMax])
posMax = i;
}
if (posMax < posMin)
{
posMin = posMax;
for (int i = 1; i < N; i++)
relAns[i] *= -1;
}
for (int i = 0; i < N; i++)
answer(i + 1, relAns[i] - relAns[posMin] + 1);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |