# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
566061 | 2022-05-21T17:41:52 Z | Waratpp123 | Swap (BOI16_swap) | C++14 | 0 ms | 212 KB |
#include<bits/stdc++.h> using namespace std; int a[200010],n,d; int play(int i,int k){ if(2*i>n) return i; int l=2*i; int r=2*i+1; if(a[i]<a[l]&&a[i]<a[r]) return i; if(a[i]>a[l]&&a[r]>a[l]) { return play(l,k); } int pl=play(l,k),pr=play(r,k); if(pl<pr) d=l; else d=r; return min(pl,pr); } int main(){ int i,l,r,x,y,j; scanf("%d",&n); for(i=1;i<=n;i++){ scanf("%d",&a[i]); } if(n%2==0) a[n+1]=99999999; for(i=1;2*i<=n;i++){ l=2*i; r=2*i+1; if(a[i]<a[l]&&a[i]<a[r]) continue; if(a[l]<a[i]&&a[r]>a[l]) { swap(a[i],a[l]); continue; } x=min(a[l],a[i]); y=max(a[l],a[i]); a[i]=a[r]; play(i,x); if(d==l) a[l]=x,a[r]=y; else a[l]=y,a[r]=x; } for(i=1;i<=n;i++){ printf("%d ",a[i]); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |