# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
784262 | tvladm2009 | Xylophone (JOI18_xylophone) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
/// i almost made my last submission to pass
const int N = 5000 + 7;
int n;
int d2[N];
int d3[N];
int dir[N];
bool same[N];
int a[N];
int b[N];
int where[N];
bool isok() {
int mn = a[1];
for (int i = 1; i < n; i++) {
a[i + 1] = a[i] + dir[i] * d2[i];
mn = min(mn, a[i + 1]);
}
for (int i = 1; i <= n; i++) {
a[i] -= (mn - 1);
}
for (int i = 1; i <= n; i++) {
where[i] = 0;
}
for (int i = 1; i <= n; i++) {
if (a[i] < 1 || a[i] > n) {
return false;
}
if (where[a[i]]) {
return false;
}
where[a[i]] = i;
}
return where[1] <= where[n];
}
void solve(int nn) {
n = nn;
for (int i = 1; i + 1 <= n; i++) {
d2[i] = query(i, i + 1);
}
for (int i = 1; i + 2 <= n; i++) {
d3[i] = query(i, i + 2);
}
/**
a[i] - a[i + 1] = +- d2[i]
**/
dir[1] = +1;
for (int i = 1; i + 2 <= n; i++) {
if (d2[i] + d2[i + 1] == d3[i]) {
/// direction[i] = direction[i + 1]
dir[i + 1] = dir[i];
} else {
/// direction[i] != direction[i + 1]
dir[i + 1] = -dir[i];
}
}
if (!isok()) {
for (int i = 1; i < n; i++) {
dir[i] *= -1;
}
assert(isok());
}
for (int i = 1; i <= n; i++) {
answer(i, a[i]);
}
return 0;
}