| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 226193 | MKopchev | Swap (BOI16_swap) | C++14 | 697 ms | 3704 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int nmax=2e5+42;
int n,inp[nmax];
int would_go(int pos,int val)
{
if(2*pos>n)return pos;
if(val<inp[2*pos]&&val<inp[2*pos+1])return pos;
if(inp[2*pos]<val&&inp[2*pos]<inp[2*pos+1])return would_go(2*pos,val);
int x=val,y=inp[2*pos];
if(x>y)swap(x,y);
if(would_go(2*pos,x)<would_go(2*pos+1,x))
{
if(val==x)return would_go(2*pos,val);
return would_go(2*pos+1,val);
}
if(val==x)return would_go(2*pos+1,val);
return would_go(2*pos,val);
}
int main()
{
scanf("%i",&n);
for(int i=1;i<=n;i++)scanf("%i",&inp[i]);
inp[n+1]=n+1;
for(int i=1;2*i+1<=n;i++)
{
if(inp[i]<inp[2*i]&&inp[i]<inp[2*i+1])continue;
if(inp[2*i]<inp[i]&&inp[2*i]<inp[2*i+1]){swap(inp[i],inp[2*i]);continue;}
int x=inp[i],y=inp[2*i],small=inp[2*i+1];
if(x>y)swap(x,y);
if(would_go(2*i,x)<would_go(2*i+1,x)){inp[2*i]=x;inp[2*i+1]=y;}
else {inp[2*i]=y;inp[2*i+1]=x;}
inp[i]=small;
}
if(n%2==0&&inp[n/2]>inp[n])swap(inp[n/2],inp[n]);
for(int i=1;i<=n;i++)
{
printf("%i",inp[i]);
if(i==n)printf("\n");
else printf(" ");
}
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... | ||||
