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>
#include <algorithm>
using namespace std;
static int A[5050];
void solve(int N) {
// gaps of 1 and 2
int d1[5050];
int d2[5050];
// O(2N) queries
for (int i = 1; i < N; i++) {
d1[i] = query(i, i + 1);
if (i < N - 1)
d2[i] = query(i, i + 2);
}
// change direction?
bool change[5050];
for (int i = 1; i < N - 1; i++) {
change[i] = !(d1[i] + d1[i + 1] == d2[i]);
}
int number = 0;
int direction = 1;
A[0] = number;
for (int i = 1; i < N; i++) {
number += d1[i] * direction;
A[i] = number;
if (i < N - 1 && change[i]) direction *= -1;
}
// min, max
int min_ = 5001, min_index = 0;
int max_ = -1, max_index = 0;
for (int i = 0; i < N; i++) {
int a = A[i];
if (a < min_) {
min_ = a;
min_index = i;
}
if (a > max_) {
max_ = a;
max_index = i;
}
}
// offset
min_--;
for (int i = 0; i < N; i++) {
A[i] -= min_;
}
// reverse
if (min_index > max_index) {
for (int i = 0; i < N; i++) {
A[i] = N - A[i] + 1;
}
}
// answer
for (int i = 1; i <= N; i++) {
answer(i, A[i - 1]);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |