# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
56149 | 2018-07-10T06:07:24 Z | 김세빈(#1581) | Swap (BOI16_swap) | C++11 | 3 ms | 488 KB |
#include <bits/stdc++.h> using namespace std; int A[22], B[22], n; void f(int p) { if(p > n){ int i; for(i=1;i<=n;i++) if(A[i] != B[i]) break; if(i <= n && A[i] < B[i]){ for(i=1;i<=n;i++) B[i] = A[i]; } return; } if((p<<1) > n) f(p+1); else if((p<<1|1) > n){ if(A[p] > A[p<<1]){ swap(A[p], A[p<<1]); f(p+1); swap(A[p], A[p<<1]); } } else{ if(A[p] < A[p<<1] && A[p] < A[p<<1|1]) f(p+1); else if(A[p<<1] < A[p<<1|1]){ swap(A[p], A[p<<1]); f(p+1); swap(A[p], A[p<<1]); } else{ swap(A[p], A[p<<1|1]); f(p+1); swap(A[p], A[p<<1|1]); swap(A[p], A[p<<1]); swap(A[p], A[p<<1|1]); f(p+1); swap(A[p], A[p<<1|1]); swap(A[p], A[p<<1]); } } } int main() { int i; scanf("%d", &n); if(n > 20) return 0; for(i=1;i<=n;i++) scanf("%d", A+i), B[i] = A[i]; f(1); for(i=1;i<=n;i++) printf("%d ", B[i]); printf("\n"); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 488 KB | Output is correct |
3 | Incorrect | 2 ms | 488 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 488 KB | Output is correct |
3 | Incorrect | 2 ms | 488 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 488 KB | Output is correct |
3 | Incorrect | 2 ms | 488 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 488 KB | Output is correct |
3 | Incorrect | 2 ms | 488 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 488 KB | Output is correct |
3 | Incorrect | 2 ms | 488 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |