# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
258617 |
2020-08-06T08:55:22 Z |
임성재(#5051) |
Swap (BOI16_swap) |
C++17 |
|
1000 ms |
6008 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[800010];
int ans[800010];
int f(int x) {
if(min({a[x], a[x*2], a[x*2+1]}) == a[x]) return x;
if(min({a[x], a[x*2], a[x*2+1]}) == a[x*2]) {
swap(a[x], a[x*2]);
int ret = f(x*2);
swap(a[x], a[x*2]);
return ret;
}
else {
swap(a[x], a[x*2+1]);
int p, q;
if(min(a[x*2], a[x*2+1]) == a[x*2+1]) {
q = f(x * 2 + 1);
swap(a[x*2], a[x*2+1]);
p = f(x*2);
swap(a[x*2], a[x*2+1]);
swap(a[x], a[x*2+1]);
return min(p, q);
}
else {
p = f(x*2);
swap(a[x*2], a[x*2+1]);
q = f(x * 2 + 1);
int ret;
if(p < q) {
swap(a[x*2], a[x*2+1]);
ret = f(x * 2 + 1);
}
else {
ret = f(x*2);
swap(a[x*2], a[x*2+1]);
}
swap(a[x], a[x*2+1]);
return ret;
}
}
}
void g(int x) {
if(x > n) return;
if(min({a[x], a[x*2], a[x*2+1]}) == a[x]);
else if(min({a[x], a[x*2], a[x*2+1]}) == a[x*2]) {
swap(a[x], a[x*2]);
}
else {
swap(a[x], a[x*2+1]);
int p, q;
if(min(a[x*2], a[x*2+1]) == a[x*2]) p = f(x*2);
else q = f(x * 2 + 1);
swap(a[x*2], a[x*2+1]);
if(min(a[x*2], a[x*2+1]) == a[x*2]) p = f(x*2);
else q = f(x * 2 + 1);
if(p < q && a[x*2] > a[x*2+1]) swap(a[x*2], a[x*2+1]);
else if(p > q && a[x*2] < a[x*2+1]) swap(a[x*2], a[x*2+1]);
}
g(x*2);
g(x*2+1);
}
int main() {
fast;
cin >> n;
for(int i=1; i<=4*n; i++) {
a[i] = i;
}
for(int i=1; i<=n; i++) {
cin >> a[i];
}
g(1);
for(int i=1; i<=n; i++) {
cout << a[i] << " ";
}
}
Compilation message
swap.cpp: In function 'void g(int)':
swap.cpp:97:8: warning: 'q' may be used uninitialized in this function [-Wmaybe-uninitialized]
else if(p > q && a[x*2] < a[x*2+1]) swap(a[x*2], a[x*2+1]);
^~
swap.cpp:97:8: warning: 'p' may be used uninitialized in this function [-Wmaybe-uninitialized]
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
11 ms |
1664 KB |
Output is correct |
17 |
Correct |
12 ms |
1664 KB |
Output is correct |
18 |
Correct |
12 ms |
1664 KB |
Output is correct |
19 |
Correct |
204 ms |
1656 KB |
Output is correct |
20 |
Correct |
186 ms |
1672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
11 ms |
1664 KB |
Output is correct |
17 |
Correct |
12 ms |
1664 KB |
Output is correct |
18 |
Correct |
12 ms |
1664 KB |
Output is correct |
19 |
Correct |
204 ms |
1656 KB |
Output is correct |
20 |
Correct |
186 ms |
1672 KB |
Output is correct |
21 |
Correct |
55 ms |
5992 KB |
Output is correct |
22 |
Correct |
47 ms |
6008 KB |
Output is correct |
23 |
Correct |
46 ms |
6008 KB |
Output is correct |
24 |
Execution timed out |
1087 ms |
4736 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |