# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
240310 | karma | Swap (BOI16_swap) | C++14 | 62 ms | 7288 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb emplace_back
#define ll long long
#define fi first
#define se second
#define mp make_pair
//#define int int64_t
using namespace std;
const int N = int(5e5) + 7;
const int logN = 18;
typedef pair<int, int> pii;
int n, a[N], b[N], can[N];
int get(int x) {
for(int res = 1e9; ; x >>= 1) {
if(can[x] != 1) res = min(res, a[x]);
if(can[x] == 0) return res;
if((x & 1) && can[x ^ 1]) {
res = min(res, a[x ^ 1]);
if(can[x ^ 1] == 1) return res;
}
}
return 1e9;
}
void change(int x, int v) {
for(;; x >>= 1) {
if(a[x] == v) {
can[x] = 0;
return;
}
if(x & 1) {
if(a[x ^ 1] == v) {
can[x] = can[x ^ 1] = 1;
return;
} else can[x ^ 1] = 0;
}
can[x] = 1;
}
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#define Task "test"
if(fopen(Task".inp", "r")) {
freopen(Task".inp", "r", stdin);
freopen(Task".out", "w", stdout);
}
cin >> n; fill_n(a, N, 1e9);
for(int i = 1; i <= n; ++i) cin >> a[i], can[i] = i == 1? 0: 2;
for(int x, i = 1; i <= n; ++i) {
b[i] = min({x = get(i), a[i << 1], a[i << 1 | 1]});
if(b[i] == x) {
change(i, x);
can[i << 1] = can[i << 1 | 1] = 0;
} else if(b[i] == a[i << 1]) can[i << 1] = 1, can[i << 1 | 1] = 0;
else can[i << 1 | 1] = 1;
}
for(int i = 1; i <= n; ++i) cout << b[i] << ' ';
}
컴파일 시 표준 에러 (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... |