Submission #27077

# Submission time Handle Problem Language Result Execution time Memory
27077 2017-07-09T07:28:13 Z 서규호(#1119) Swap (BOI16_swap) C++11
21 / 100
1000 ms 8464 KB
#include <bits/stdc++.h>

#define lld long long
#define pii pair<int,int>
#define pb push_back
#define next nextt
#define Inf 1000000000
#define Linf 1000000000000000000LL
#define Mod 1000000007

using namespace std;

int N;
int a[200002],ans[200002];
bool check[200002];
set<int> q;
vector<int> tmp[200002];

void dfs(int lev){
	if(lev == N+1){
		bool flag = false;
		for(int i=1; i<=N; i++){
			if(a[i] < ans[i]){
				flag = true;
				break;
			}else if(a[i] > ans[i]){
				flag = false;
				break;
			}
		}
		if(flag) for(int i=1; i<=N; i++) ans[i] = a[i];
		return;
	}
	if(lev == N){
	dfs(lev+1);
	swap(a[lev/2],a[lev]);
	dfs(lev+1);
	swap(a[lev/2],a[lev]);
	}else{
		if(a[lev/2] < a[lev] && a[lev/2] < a[lev+1]){
			dfs(lev+2);
		}else if(a[lev] < a[lev/2] && a[lev] < a[lev+1]){
			swap(a[lev/2],a[lev]);
			dfs(lev+2);
			swap(a[lev/2],a[lev]);
		}else{
			swap(a[lev/2],a[lev]);
			swap(a[lev/2],a[lev+1]);
			dfs(lev+2);
			swap(a[lev/2],a[lev+1]);
			swap(a[lev/2],a[lev]);
			
			swap(a[lev/2],a[lev+1]);
			dfs(lev+2);
			swap(a[lev/2],a[lev+1]);
		}
	}
}

int main(){
    //freopen("input.txt","r",stdin);
	scanf("%d",&N);
	for(int i=1; i<=N; i++){
		scanf("%d",&a[i]);
		ans[i] = a[i];
	}
	dfs(2);
   	for(int i=1; i<=N; i++) printf("%d ",ans[i]);

	return 0;
}

Compilation message

swap.cpp: In function 'int main()':
swap.cpp:62:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&N);
                ^
swap.cpp:64:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&a[i]);
                    ^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8464 KB Output is correct
2 Correct 3 ms 8464 KB Output is correct
3 Correct 3 ms 8464 KB Output is correct
4 Correct 0 ms 8464 KB Output is correct
5 Correct 0 ms 8464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8464 KB Output is correct
2 Correct 3 ms 8464 KB Output is correct
3 Correct 3 ms 8464 KB Output is correct
4 Correct 0 ms 8464 KB Output is correct
5 Correct 0 ms 8464 KB Output is correct
6 Correct 3 ms 8464 KB Output is correct
7 Correct 0 ms 8464 KB Output is correct
8 Correct 0 ms 8464 KB Output is correct
9 Correct 9 ms 8464 KB Output is correct
10 Correct 0 ms 8464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8464 KB Output is correct
2 Correct 3 ms 8464 KB Output is correct
3 Correct 3 ms 8464 KB Output is correct
4 Correct 0 ms 8464 KB Output is correct
5 Correct 0 ms 8464 KB Output is correct
6 Correct 3 ms 8464 KB Output is correct
7 Correct 0 ms 8464 KB Output is correct
8 Correct 0 ms 8464 KB Output is correct
9 Correct 9 ms 8464 KB Output is correct
10 Correct 0 ms 8464 KB Output is correct
11 Execution timed out 1000 ms 8464 KB Execution timed out
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8464 KB Output is correct
2 Correct 3 ms 8464 KB Output is correct
3 Correct 3 ms 8464 KB Output is correct
4 Correct 0 ms 8464 KB Output is correct
5 Correct 0 ms 8464 KB Output is correct
6 Correct 3 ms 8464 KB Output is correct
7 Correct 0 ms 8464 KB Output is correct
8 Correct 0 ms 8464 KB Output is correct
9 Correct 9 ms 8464 KB Output is correct
10 Correct 0 ms 8464 KB Output is correct
11 Execution timed out 1000 ms 8464 KB Execution timed out
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8464 KB Output is correct
2 Correct 3 ms 8464 KB Output is correct
3 Correct 3 ms 8464 KB Output is correct
4 Correct 0 ms 8464 KB Output is correct
5 Correct 0 ms 8464 KB Output is correct
6 Correct 3 ms 8464 KB Output is correct
7 Correct 0 ms 8464 KB Output is correct
8 Correct 0 ms 8464 KB Output is correct
9 Correct 9 ms 8464 KB Output is correct
10 Correct 0 ms 8464 KB Output is correct
11 Execution timed out 1000 ms 8464 KB Execution timed out
12 Halted 0 ms 0 KB -