# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
258606 |
2020-08-06T08:36:32 Z |
임성재(#5051) |
Swap (BOI16_swap) |
C++17 |
|
1 ms |
384 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 > n/2) {
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+1);
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<=2*n; 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]
}
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |