| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1306895 | teamcuddlepie | Xylophone (JOI18_xylophone) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
// These are provided by the grader (do NOT implement them)
int query(int l, int r);
void answer(vector<int> A);
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
vector<int> d(N - 1);
// 1) Adjacent differences
for (int i = 0; i < N - 1; i++) {
d[i] = query(i + 1, i + 2);
}
// sign[i] = +1 if A[i+1] > A[i], -1 otherwise
vector<int> sign(N - 1);
sign[0] = 1; // arbitrarily assume increasing at first
// 2) Determine directions using triples
for (int i = 0; i < N - 2; i++) {
int t = query(i + 1, i + 3);
if (t == d[i] + d[i + 1]) {
// same direction
sign[i + 1] = sign[i];
} else {
// direction flips
sign[i + 1] = -sign[i];
}
}
// 3) Build relative values
vector<int> b(N);
b[0] = 0;
for (int i = 1; i < N; i++) {
b[i] = b[i - 1] + sign[i - 1] * d[i - 1];
}
// 4) Normalize to permutation 1..N
int mn = *min_element(b.begin(), b.end());
for (int i = 0; i < N; i++) {
b[i] -= mn;
}
// Now b contains values from 0..N-1 (in some order)
vector<int> A(N);
for (int i = 0; i < N; i++) {
A[i] = b[i] + 1;
}
// Output answer
answer(A);
return 0;
}
