| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 258599 | IOrtroiii | Swap (BOI16_swap) | C++14 | 62 ms | 5628 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MX = 400400;
int N;
int A[MX];
int state[MX];
int ans[MX];
int query(int i) {
int ans = MX;
for (; i > 0; i /= 2) {
if (state[i] != 1) ans = min(ans, A[i]);
if (state[i] == 0) return ans;
if (i % 2 && state[i - 1] != 0) {
ans = min(ans, A[i - 1]);
if (state[i - 1] == 1) return ans;
}
}
}
void modify(int i, int val) {
for (; i > 0; i /= 2) {
if (A[i] == val) {
state[i] = 0;
return;
}
if (i % 2) {
if (A[i - 1] == val) {
state[i] = state[i - 1] = 1;
return;
} else state[i - 1] = 0;
}
state[i] = 1;
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr);
cin >> N;
for (int i = 1; i <= N; ++i) cin >> A[i];
for (int i = N + 1; i <= 2 * N + 1; ++i) A[i] = MX;
state[1] = 0; for (int i = 2; i <= 2 * N + 1; ++i) state[i] = -1;
for (int i = 1; i <= N; ++i) {
int val = query(i);
ans[i] = min({val, A[i * 2], A[i * 2 + 1]});
if (ans[i] == val) {
modify(i, val);
state[i * 2] = 0;
state[i * 2 + 1] = 0;
} else if (ans[i] == A[i * 2]) {
state[i * 2] = 1;
state[i * 2 + 1] = 0;
} else {
assert(ans[i] == A[i * 2 + 1]);
state[i * 2 + 1] = 1;
}
}
for (int i = 1; i <= N; ++i) cout << ans[i] << ' '; cout << '\n';
return 0;
}
컴파일 시 표준 에러 (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... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
