# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
626904 |
2022-08-12T00:26:12 Z |
chonka |
Swap (BOI16_swap) |
C++17 |
|
0 ms |
212 KB |
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int MAXN = 2e5 + 7 ;
int n ;
int a[ MAXN ] ;
int get ( int wh , int val ) {
if ( 2 * wh > n ) { return wh ; }
if ( 2 * wh == n ) {
if ( val < a[ 2 * wh ] ) { return wh ; }
return 2 * wh ;
}
if ( val < a[ 2 * wh ] && val < a[ 2 * wh + 1 ] ) { return wh ; }
if ( a[ 2 * wh ] < val && a[ 2 * wh ] < a[ 2 * wh + 1 ] ) {
return get ( 2 * wh , val ) ;
}
int x = a[ 2 * wh ] ;
if ( x < val ) {
int sr1 = get ( 2 * wh , x ) ;
int sr2 = get ( 2 * wh + 1 , x ) ;
if ( sr1 < sr2 ) {
return get ( 2 * wh + 1 , val ) ;
}
else {
return get ( 2 * wh , val ) ;
}
}
else {
int sr1 = get ( 2 * wh , x ) ;
int sr2 = get ( 2 * wh + 1 , x ) ;
return min ( sr1 , sr2 ) ;
}
}
void solve ( ) {
cin >> n ;
for ( int i = 1 ; i <= n ; ++ i ) {
cin >> a[ i ] ;
}
for ( int i = 1 ; i <= n ; ++ i ) {
if ( 2 * i > n ) { continue ; }
if ( 2 * i == n ) {
if ( a[ i ] > a[ 2 * i ] ) {
swap ( a[ i ] , a[ 2 * i ] ) ;
}
continue ;
}
if ( a[ i ] < a[ 2 * i ] && a[ i ] < a[ 2 * i + 1 ] ) { continue ; }
if ( a[ 2 * i ] < a[ i ] && a[ 2 * i ] < a[ i ] ) {
swap ( a[ i ] , a[ 2 * i ] ) ;
continue ;
}
swap ( a[ i ] , a[ 2 * i + 1 ] ) ;
if ( a[ 2 * i ] < a[ 2 * i + 1 ] ) {
int sr1 = get ( 2 * i , a[ 2 * i ] ) ;
int sr2 = get ( 2 * i + 1 , a[ 2 * i ] ) ;
if ( sr2 < sr1 ) {
swap ( a[ 2 * i ] , a[ 2 * i + 1 ] ) ;
}
}
else {
int sr1 = get ( 2 * i , a[ 2 * i + 1 ] ) ;
int sr2 = get ( 2 * i + 1 , a[ 2 * i + 1 ] ) ;
if ( sr1 < sr2 ) {
swap ( a[ 2 * i ] , a[ 2 * i + 1 ] ) ;
}
}
}
for ( int i = 1 ; i <= n ; ++ i ) {
cout << a[ i ] << " " ;
}
cout << "\n" ;
}
int main ( ) {
ios_base :: sync_with_stdio ( false ) ;
cin.tie ( NULL ) ;
int t = 1 ; // cin >> t ;
while ( t -- ) { solve ( ) ; }
return 0 ;
}
# |
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 |
- |