# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
258609 |
2020-08-06T08:41:14 Z |
임성재(#5051) |
Swap (BOI16_swap) |
C++17 |
|
1000 ms |
512 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];
int ans[111];
bool chk[111];
int dfs(int x) {
if(x > n) {
bool flag = false;
for(int i=1; i<=n; i++) {
if(a[i] > ans[i]) flag = false;
else if(a[i] < ans[i]) flag = true;
else continue;
break;
}
if(flag) {
for(int i=1; i<=n; i++) {
ans[i] = a[i];
}
}
return 0;
}
if(x >= 22) {
if(min({a[x/2], a[x/2*2], a[x/2 * 2 + 1]}) == a[x/2*2]) swap(a[x/2], a[x/2*2]), chk[x/2*2] = true;
else if(min({a[x/2], a[x/2*2], a[x/2 * 2 + 1]}) == a[x/2*2+1]) {
swap(a[x/2], a[x/2*2+1]), chk[x/2*2+1] = true;
if(a[x/2*2] > a[x/2*2+1]) swap(a[x/2*2], a[x/2*2+1]), chk[x/2*2] = true;
}
dfs(x+2);
if(chk[x/2*2+1]) swap(a[x/2], a[x/2*2+1]);
if(chk[x/2*2]) swap(a[x/2], a[x/2*2]);
chk[x/2*2] = chk[x/2*2+1] = false;
}
else {
dfs(x+1);
swap(a[x/2], a[x]);
dfs(x+1);
swap(a[x/2], a[x]);
}
}
int main() {
fast;
cin >> n;
for(int i=1; i<=100; i++)
a[i] = i;
for(int i=1; i<=n; i++) {
cin >> a[i];
ans[i] = a[i];
}
dfs(2);
for(int i=1; i<=n; i++) {
cout << ans[i] << " ";
}
}
Compilation message
swap.cpp: In function 'int dfs(int)':
swap.cpp:65:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
7 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
7 ms |
384 KB |
Output is correct |
5 |
Correct |
6 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
7 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
7 ms |
384 KB |
Output is correct |
5 |
Correct |
6 ms |
384 KB |
Output is correct |
6 |
Correct |
114 ms |
384 KB |
Output is correct |
7 |
Correct |
146 ms |
384 KB |
Output is correct |
8 |
Correct |
127 ms |
424 KB |
Output is correct |
9 |
Correct |
126 ms |
384 KB |
Output is correct |
10 |
Correct |
123 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
7 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
7 ms |
384 KB |
Output is correct |
5 |
Correct |
6 ms |
384 KB |
Output is correct |
6 |
Correct |
114 ms |
384 KB |
Output is correct |
7 |
Correct |
146 ms |
384 KB |
Output is correct |
8 |
Correct |
127 ms |
424 KB |
Output is correct |
9 |
Correct |
126 ms |
384 KB |
Output is correct |
10 |
Correct |
123 ms |
512 KB |
Output is correct |
11 |
Execution timed out |
1026 ms |
416 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
7 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
7 ms |
384 KB |
Output is correct |
5 |
Correct |
6 ms |
384 KB |
Output is correct |
6 |
Correct |
114 ms |
384 KB |
Output is correct |
7 |
Correct |
146 ms |
384 KB |
Output is correct |
8 |
Correct |
127 ms |
424 KB |
Output is correct |
9 |
Correct |
126 ms |
384 KB |
Output is correct |
10 |
Correct |
123 ms |
512 KB |
Output is correct |
11 |
Execution timed out |
1026 ms |
416 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
7 ms |
384 KB |
Output is correct |
3 |
Correct |
6 ms |
384 KB |
Output is correct |
4 |
Correct |
7 ms |
384 KB |
Output is correct |
5 |
Correct |
6 ms |
384 KB |
Output is correct |
6 |
Correct |
114 ms |
384 KB |
Output is correct |
7 |
Correct |
146 ms |
384 KB |
Output is correct |
8 |
Correct |
127 ms |
424 KB |
Output is correct |
9 |
Correct |
126 ms |
384 KB |
Output is correct |
10 |
Correct |
123 ms |
512 KB |
Output is correct |
11 |
Execution timed out |
1026 ms |
416 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |