# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
258533 |
2020-08-06T05:41:49 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<pii> g[100010];
int main() {
fast;
cin >> n;
for(int i=1; i<=n; i++) {
cin >> a[i];
if(i > 1) g[i/2].insert(mp(i, i)), g[i].insert(mp(i, i/2));
}
for(int i=1; i<=n; i++) {
int mn = a[i];
int x = i;
for(auto it : g[i]) {
g[it.se].erase(mp(it.fi, i));
if(a[it.se] < mn) {
x = it.se;
mn = a[it.se];
}
mn = min(mn, a[it.se]);
}
swap(a[x], a[i]);
if(x == i) continue;
for(auto it : g[i]) {
if(it.se == x) break;
g[x].insert(it);
g[it.se].insert(mp(it.fi, x));
}
}
for(int i=1; i<=n; i++) {
cout << a[i] << " ";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4992 KB |
Output is correct |
2 |
Correct |
5 ms |
4992 KB |
Output is correct |
3 |
Incorrect |
3 ms |
4992 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4992 KB |
Output is correct |
2 |
Correct |
5 ms |
4992 KB |
Output is correct |
3 |
Incorrect |
3 ms |
4992 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4992 KB |
Output is correct |
2 |
Correct |
5 ms |
4992 KB |
Output is correct |
3 |
Incorrect |
3 ms |
4992 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4992 KB |
Output is correct |
2 |
Correct |
5 ms |
4992 KB |
Output is correct |
3 |
Incorrect |
3 ms |
4992 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4992 KB |
Output is correct |
2 |
Correct |
5 ms |
4992 KB |
Output is correct |
3 |
Incorrect |
3 ms |
4992 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |