# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
112166 | 2019-05-17T16:51:15 Z | Bruteforceman | Swap (BOI16_swap) | C++11 | 11 ms | 10496 KB |
#include "bits/stdc++.h" using namespace std; int n; int a[400010]; set <int> s[200010]; int match[200010]; int main(int argc, char const *argv[]) { scanf("%d", &n); for(int i = 1; i <= n; i++) { scanf("%d", &a[i]); } for(int i = n+1; i <= 2*n+1; i++) { a[i] = INT_MAX; } memset(match, -1, sizeof match); // for(int i = 1; i <= (n / 2); i++) { // int l = i << 1; // int r = l + 1; // if(l <= n) cout << a[i] << ' ' << a[l] << endl; // if(r <= n) cout << a[i] << ' ' << a[r] << endl; // } for(int i = 1; i <= n; i++) { int l = i << 1; int r = l + 1; int val = a[i]; if(a[i] == -1) { int cur = i; val = INT_MAX; while(cur >= 1) { if(!s[cur].empty()) { val = min(val, *s[cur].begin()); } cur /= 2; } } if(val < min(a[l], a[r])) { if(a[i] == -1) { int cur = i; while(cur > 1) { int now = cur; cur /= 2; if(s[cur].find(val) != s[cur].end()) { s[cur].erase(val); s[cur].erase(match[val]); if(match[val] != -1) { s[now ^ 1].insert(match[val]); match[match[val]] = -1; } break; } } if(s[i].find(val) != s[i].end()) { s[i].erase(val); } } a[i] = val; } else if (a[l] < a[r]) { swap(a[i], a[l]); } else { swap(a[i], a[r]); if(a[l] != -1) s[i].insert(a[l]); if(a[r] != -1) s[i].insert(a[r]); if(a[l] != -1 && a[r] != -1) { match[a[l]] = a[r]; match[a[r]] = a[l]; } a[l] = a[r] = -1; } } for(int i = 1; i <= n; i++) { printf("%d ", a[i]); } printf("\n"); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 10496 KB | Output is correct |
2 | Correct | 10 ms | 10496 KB | Output is correct |
3 | Incorrect | 10 ms | 10496 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 10496 KB | Output is correct |
2 | Correct | 10 ms | 10496 KB | Output is correct |
3 | Incorrect | 10 ms | 10496 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 10496 KB | Output is correct |
2 | Correct | 10 ms | 10496 KB | Output is correct |
3 | Incorrect | 10 ms | 10496 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 10496 KB | Output is correct |
2 | Correct | 10 ms | 10496 KB | Output is correct |
3 | Incorrect | 10 ms | 10496 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 10496 KB | Output is correct |
2 | Correct | 10 ms | 10496 KB | Output is correct |
3 | Incorrect | 10 ms | 10496 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |