# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
226193 |
2020-04-22T19:28:18 Z |
MKopchev |
Swap (BOI16_swap) |
C++14 |
|
697 ms |
3704 KB |
#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;
}
Compilation message
swap.cpp: In function 'int main()':
swap.cpp:30:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i",&n);
~~~~~^~~~~~~~~
swap.cpp:31:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i=1;i<=n;i++)scanf("%i",&inp[i]);
~~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
4 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
256 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
4 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
256 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
4 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
256 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
256 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
4 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
256 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
256 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
19 ms |
1152 KB |
Output is correct |
17 |
Correct |
19 ms |
1152 KB |
Output is correct |
18 |
Correct |
27 ms |
1144 KB |
Output is correct |
19 |
Correct |
91 ms |
1148 KB |
Output is correct |
20 |
Correct |
87 ms |
1144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
4 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
256 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
256 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
19 ms |
1152 KB |
Output is correct |
17 |
Correct |
19 ms |
1152 KB |
Output is correct |
18 |
Correct |
27 ms |
1144 KB |
Output is correct |
19 |
Correct |
91 ms |
1148 KB |
Output is correct |
20 |
Correct |
87 ms |
1144 KB |
Output is correct |
21 |
Correct |
65 ms |
3704 KB |
Output is correct |
22 |
Correct |
66 ms |
3704 KB |
Output is correct |
23 |
Correct |
64 ms |
3680 KB |
Output is correct |
24 |
Correct |
697 ms |
3704 KB |
Output is correct |
25 |
Correct |
685 ms |
3700 KB |
Output is correct |