# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
258523 |
2020-08-06T05:32:41 Z |
임성재(#5051) |
Swap (BOI16_swap) |
C++17 |
|
5 ms |
4992 KB |
#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false); cin.tie(NULL)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace
#define all(v) (v).begin(), (v).end()
#define pre(a) cout<<fixed; cout.precision(a)
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf = 1e9;
const ll INF = 1e18;
int n;
int a[100010];
set<int> g[100010];
int main() {
fast;
cin >> n;
for(int i=1; i<=n; i++) {
cin >> a[i];
if(i > 1) g[i/2].insert(i), g[i].insert(i/2);
}
for(int i=1; i<=n; i++) {
int mn = a[i];
for(auto it : g[i]) {
g[it].erase(i);
mn = min(mn, a[it]);
}
if(mn == a[i]) continue;
bool flag = false;
int x;
for(auto it : g[i]) {
if(mn == a[it]) {
x = it;
flag = true;
break;
}
}
swap(a[x], a[i]);
for(auto it : g[i]) {
if(it == x) break;
g[x].insert(it);
g[it].insert(x);
}
}
for(int i=1; i<=n; i++) {
cout << a[i] << " ";
}
}
Compilation message
swap.cpp: In function 'int main()':
swap.cpp:45:8: warning: variable 'flag' set but not used [-Wunused-but-set-variable]
bool flag = false;
^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4992 KB |
Output is correct |
2 |
Correct |
4 ms |
4992 KB |
Output is correct |
3 |
Incorrect |
4 ms |
4992 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4992 KB |
Output is correct |
2 |
Correct |
4 ms |
4992 KB |
Output is correct |
3 |
Incorrect |
4 ms |
4992 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4992 KB |
Output is correct |
2 |
Correct |
4 ms |
4992 KB |
Output is correct |
3 |
Incorrect |
4 ms |
4992 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4992 KB |
Output is correct |
2 |
Correct |
4 ms |
4992 KB |
Output is correct |
3 |
Incorrect |
4 ms |
4992 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4992 KB |
Output is correct |
2 |
Correct |
4 ms |
4992 KB |
Output is correct |
3 |
Incorrect |
4 ms |
4992 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |