# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
198583 | rKrPaN | Xylophone (JOI18_xylophone) | C++98 | 0 ms | 0 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 <algorithm>
using namespace std;
static int niz[5000];
int Q[5000][2];
void solve(int N) {
for (int i = 1; i <= N-1; i++){
Q[i][1] = query(i, i+1);
}
for (int i = 1; i <= N-2; i++){
Q[i][2] = query(i, i+2);#include "xylophone.h"
static int niz[5000];
int Q[5000][2];
void solve(int N) {
for (int i = 1; i <= N-1; i++){
Q[i][1] = query(i, i+1);
}
for (int i = 1; i <= N-2; i++){
Q[i][2] = query(i, i+2);
}
niz[2] = Q[1][1];
for (int i = 3; i <= N; i++){
if (Q[i-2][2] == Q[i-2][1] + Q[i-1][1]){
if (niz[i-2] < niz[i-1])niz[i] = niz[i-1] + Q[i-1][1];
else niz[i] = niz[i-1] - Q[i-1][1];
}
if (Q[i-2][2] == max(Q[i-2][1], Q[i-1][1])){
if (niz[i-2] < niz[i-1])niz[i] = niz[i-1] - Q[i-1][1];
else niz[i] = niz[i-1] + Q[i-1][1];
}
}
int mn = 5010;
int mx = -5010;
int plus;
int inv = 1;
for (int i = 1; i <= N; i++){
if (niz[i] < mn)mn = niz[i];
if (niz[i] > mx)mx = niz[i];
}
plus = -mn+1;
for (int i = 1; i <= N; i++){
if (niz[i] == mn)break;
if (niz[i] == mn + N-1){
inv = -1;
plus = mx+1;
break;
}
}
for (int i = 1; i <= N; i++){
answer (i, inv*niz[i] + plus);
}
}
}
niz[2] = Q[1][1];
for (int i = 3; i <= N; i++){
if (Q[i-2][2] == Q[i-2][1] + Q[i-1][1]){
if (niz[i-2] < niz[i-1])niz[i] = niz[i-1] + Q[i-1][1];
else niz[i] = niz[i-1] - Q[i-1][1];
}
if (Q[i-2][2] == max(Q[i-2][1], Q[i-1][1])){
if (niz[i-2] < niz[i-1])niz[i] = niz[i-1] - Q[i-1][1];
else niz[i] = niz[i-1] + Q[i-1][1];
}
}
int mn = 5010;
int mx = -5010;
int plus;
int inv = 1;
for (int i = 1; i <= N; i++){
if (niz[i] < mn)mn = niz[i];
if (niz[i] > mx)mx = niz[i];
}
plus = -mn+1;
for (int i = 1; i <= N; i++){
if (niz[i] == mn)break;
if (niz[i] == mn + N-1){
inv = -1;
plus = mx+1;
break;
}
}
for (int i = 1; i <= N; i++){
answer (i, inv*niz[i] + plus);
}
}