# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
798884 |
2023-07-31T06:21:52 Z |
boyliguanhan |
Swap (BOI16_swap) |
C++17 |
|
2 ms |
1876 KB |
#include<bits/stdc++.h>
#define T(a,b,c) make_tuple(a,b,c)
using namespace std;
int arr[400100],n;
int pushed(int i,int v){
if(i*2>n)
return 0;
int v2 = arr[2*i];
if(i*2==n)
return v2<v;
int v3=arr[2*i+1];
if(v<v2 && v<v3)
return 0;
if(v2<v && v2<v3)
return 1 + pushed(2*i,v);
if(v<v2)
return min(pushed(2*i,v),pushed(2*i+1,v))+1;
int l1 = pushed(2*i,v2),l2 = pushed(2*i+1,v2);
if(l1 <= l2)
return 1+pushed(2*i+1,v);
return 1+pushed(2*i,v);
}
int main() {
memset(arr, 7, sizeof arr);
cin >> n;
for(int i = 1; i <= n; i++)
cin >> arr[i];
for(int i = 1; i <= n; i++) {
int &a=arr[i],&b=arr[i*2],&c=arr[i*2+1];
if(a>b||a>c){
if(b<c)
swap(a,b);
else {
int a2=a,b2=b,c2=c;
if(a2>b2)
swap(a2,b2);
if(pushed(2*i,a)>pushed(2*i+1,a)) swap(a2,b2);
a = c2;
b = a2;
c = b2;
}
}
cout << a << (i<n?' ':'\n');
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
1 ms |
1872 KB |
Output is correct |
3 |
Correct |
1 ms |
1876 KB |
Output is correct |
4 |
Correct |
2 ms |
1868 KB |
Output is correct |
5 |
Correct |
1 ms |
1876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
1 ms |
1872 KB |
Output is correct |
3 |
Correct |
1 ms |
1876 KB |
Output is correct |
4 |
Correct |
2 ms |
1868 KB |
Output is correct |
5 |
Correct |
1 ms |
1876 KB |
Output is correct |
6 |
Correct |
1 ms |
1876 KB |
Output is correct |
7 |
Correct |
1 ms |
1748 KB |
Output is correct |
8 |
Correct |
1 ms |
1876 KB |
Output is correct |
9 |
Correct |
1 ms |
1876 KB |
Output is correct |
10 |
Correct |
1 ms |
1876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
1 ms |
1872 KB |
Output is correct |
3 |
Correct |
1 ms |
1876 KB |
Output is correct |
4 |
Correct |
2 ms |
1868 KB |
Output is correct |
5 |
Correct |
1 ms |
1876 KB |
Output is correct |
6 |
Correct |
1 ms |
1876 KB |
Output is correct |
7 |
Correct |
1 ms |
1748 KB |
Output is correct |
8 |
Correct |
1 ms |
1876 KB |
Output is correct |
9 |
Correct |
1 ms |
1876 KB |
Output is correct |
10 |
Correct |
1 ms |
1876 KB |
Output is correct |
11 |
Incorrect |
1 ms |
1868 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
1 ms |
1872 KB |
Output is correct |
3 |
Correct |
1 ms |
1876 KB |
Output is correct |
4 |
Correct |
2 ms |
1868 KB |
Output is correct |
5 |
Correct |
1 ms |
1876 KB |
Output is correct |
6 |
Correct |
1 ms |
1876 KB |
Output is correct |
7 |
Correct |
1 ms |
1748 KB |
Output is correct |
8 |
Correct |
1 ms |
1876 KB |
Output is correct |
9 |
Correct |
1 ms |
1876 KB |
Output is correct |
10 |
Correct |
1 ms |
1876 KB |
Output is correct |
11 |
Incorrect |
1 ms |
1868 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
1 ms |
1872 KB |
Output is correct |
3 |
Correct |
1 ms |
1876 KB |
Output is correct |
4 |
Correct |
2 ms |
1868 KB |
Output is correct |
5 |
Correct |
1 ms |
1876 KB |
Output is correct |
6 |
Correct |
1 ms |
1876 KB |
Output is correct |
7 |
Correct |
1 ms |
1748 KB |
Output is correct |
8 |
Correct |
1 ms |
1876 KB |
Output is correct |
9 |
Correct |
1 ms |
1876 KB |
Output is correct |
10 |
Correct |
1 ms |
1876 KB |
Output is correct |
11 |
Incorrect |
1 ms |
1868 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |