답안 #258607

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
258607 2020-08-06T08:38:51 Z 임성재(#5051) Swap (BOI16_swap) C++17
10 / 100
117 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 > 20) {
		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<=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]
 }
 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 384 KB Output is correct
2 Correct 7 ms 384 KB Output is correct
3 Correct 7 ms 384 KB Output is correct
4 Correct 7 ms 384 KB Output is correct
5 Correct 6 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 384 KB Output is correct
2 Correct 7 ms 384 KB Output is correct
3 Correct 7 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 111 ms 384 KB Output is correct
7 Incorrect 117 ms 384 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 384 KB Output is correct
2 Correct 7 ms 384 KB Output is correct
3 Correct 7 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 111 ms 384 KB Output is correct
7 Incorrect 117 ms 384 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 384 KB Output is correct
2 Correct 7 ms 384 KB Output is correct
3 Correct 7 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 111 ms 384 KB Output is correct
7 Incorrect 117 ms 384 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 384 KB Output is correct
2 Correct 7 ms 384 KB Output is correct
3 Correct 7 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 111 ms 384 KB Output is correct
7 Incorrect 117 ms 384 KB Output isn't correct
8 Halted 0 ms 0 KB -