# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
988480 |
2024-05-24T20:15:40 Z |
hyakup |
Swap (BOI16_swap) |
C++17 |
|
2 ms |
1880 KB |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
vector<int> v( maxn ), edge( maxn );
int find( int a ){ return (( edge[a] == a ) ? a : edge[a] = find(edge[a])); }
int main(){
int n; cin >> n;
vector<pair<int,int>> ordem;
for( int i = 1; i <= n; i++ ){
cin >> v[i];
edge[i] = i;
if( i > 1 ) ordem.push_back({ v[i], i });
}
sort( ordem.begin(), ordem.end() );
for( auto [val, id] : ordem ){
if( id%2 ){ // filho direito
int a = find(id), b = id/2;
if( a > b ) swap( a, b );
if( v[a] > v[b] ){
swap( v[a], v[b] );
edge[id/2] = id;
}
}
else{
int a = find(id), b = find(id/2);
if( a > b ) swap( a, b );
if( v[a] > v[b] ){
swap( v[a], v[b] );
edge[id/2] = id;
}
}
}
for( int i = 1; i <= n; i++ ) cout << v[i] << " ";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
1880 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
1880 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
1880 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
1880 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
1880 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |