# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
46815 | Bruteforceman | Swap (BOI16_swap) | C++11 | 3 ms | 1912 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
int a[100010 << 2];
int n;
const int inf = 1e9;
int func(int x) {
int ans = inf;
ans = min(ans, a[x]);
if((x << 1) <= n) ans = min(ans, a[x << 1]);
if(((x << 1) | 1) <= n) ans = min(ans, a[(x << 1) | 1]);
return ans;
}
int main(int argc, char const *argv[])
{
memset(a, -1, sizeof a);
scanf("%d", &n);
for(int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
priority_queue <int, vector <int>, greater <int>> PQ;
queue <int> Q;
Q.push(1);
while(!Q.empty()) {
int x = Q.front();
Q.pop();
int opt = PQ.empty() ? inf : PQ.top();
int f = func(x);
int l = x << 1;
int r = l + 1;
if(a[x] == inf) {
if(opt < f) {
a[x] = opt;
PQ.pop();
} else if (a[r] == f) {
swap(a[x], a[r]);
PQ.push(a[l]);
a[l] = inf;
} else {
swap(a[x], a[l]);
}
} else {
if(a[r] == f) {
PQ.push(a[x]);
PQ.push(a[l]);
a[x] = a[r];
a[l] = a[r] = inf;
} else if (a[l] == f) {
swap(a[x], a[l]);
}
}
if(l <= n) Q.push(l);
if(r <= n) Q.push(r);
}
for(int i = 1; i <= n; i++) {
printf("%d ", a[i]);
}
printf("\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... |