# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
230945 | AlexLuchianov | Xylophone (JOI18_xylophone) | C++14 | 115 ms | 632 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"
#include <iostream>
int const nmax = 5000;
static int A[5000];
int diff[1 + nmax];
int change[1 + nmax];
int v[1 + nmax];
void solve(int n) {
for(int i = 1;i < n; i++)
diff[i] = query(i, i + 1);
change[1] = 1;
for(int i = 2; i < n; i++){
if(diff[i - 1] + diff[i] == query(i - 1, i + 1))
change[i] = change[i - 1];
else
change[i] = !change[i - 1];
}
v[1] = 0;
for(int i = 2;i <= n; i++)
if(change[i - 1] == 1)
v[i] = v[i - 1] + diff[i - 1];
else
v[i] = v[i - 1] - diff[i - 1];
int smin = 0;
for(int i = 1; i <= n; i++)
smin = std::min(smin, v[i]);
for(int i = 1;i <= n; i++)
v[i] = v[i] - smin + 1;
int pos1, posn;
for(int i = 1;i <= n; i++)
if(v[i] == 1)
pos1 = i;
else if(v[i] == n)
posn = i;
if(posn < pos1)
for(int i = 1; i <= n; i++)
v[i] = n - v[i] + 1;
for(int i = 1;i <= n; i++)
answer(i, v[i]);
}
/*
5
2 1 5 3 4
*/
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... |