# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
122989 | 2019-06-29T22:57:13 Z | thebes | Swap (BOI16_swap) | C++14 | 2 ms | 376 KB |
#include <bits/stdc++.h> using namespace std; const int MN = 2e5+5; int arr[MN], n, i; int rec(int p,int v){ if(2*p>n) return p; else if(2*p+1>n) return v<arr[2*p]?p:2*p; if(v<arr[2*p]&&v<arr[2*p+1]) return p; if(arr[2*p]<v&&arr[2*p]<arr[2*p+1]) return rec(2*p,v); if(arr[2*p+1]<v&&arr[2*p+1]) return min(rec(2*p,v),rec(2*p+1,v)); } int main(){ for(scanf("%d",&n),i=1;i<=n;i++) scanf("%d",&arr[i]); for(i=1;i<=n;i++){ if(2*i>n) continue; if(2*i+1>n){ if(arr[2*i]<arr[i]) swap(arr[2*i],arr[i]); } else{ if(arr[2*i+1]<arr[i]&&arr[2*i+1]<arr[2*i]){ int a = min(arr[i],arr[2*i]); int b = max(arr[i],arr[2*i]); arr[i] = arr[2*i+1]; if(rec(2*i,a)<rec(2*i+1,a)) arr[2*i]=a,arr[2*i+1]=b; else arr[2*i+1]=a,arr[2*i]=b; } else{ if(arr[i]>arr[2*i]) swap(arr[i],arr[2*i]); if(arr[i]>arr[2*i+1]) swap(arr[i],arr[2*i+1]); } } } for(i=1;i<=n;i++) printf("%d ",arr[i]); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 256 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Incorrect | 2 ms | 256 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 256 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Incorrect | 2 ms | 256 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 256 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Incorrect | 2 ms | 256 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 256 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Incorrect | 2 ms | 256 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 256 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Incorrect | 2 ms | 256 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |