Submission #27062

# Submission time Handle Problem Language Result Execution time Memory
27062 2017-07-09T06:41:14 Z 서규호(#1119) Swap (BOI16_swap) C++14
0 / 100
3 ms 8468 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 copy(int x){
	for(auto &i : q) tmp[x].pb(i);
}

int main(){
    //freopen("input.txt","r",stdin);
	scanf("%d",&N);
	for(int i=1; i<=N; i++){
		scanf("%d",&a[i]);
	}
	for(int i=1; i<=(N-1)/2; i++){
		int t = a[i];
		if(t == 0){
			while(!q.empty()){
				if(!check[*q.begin()]) break;
				q.erase(q.begin());
			}
			t = *q.begin();
		}else q.insert(a[i]);
		ans[i] = min(t,min(a[i*2],a[i*2+1]));
		check[ans[i]] = true;
		if(a[i*2] == ans[i]){
			copy(i*2);
			a[i*2] = 0;
		}else if(a[i*2+1] == ans[i]){
			q.insert(a[i*2]);
			copy(i*2);
			copy(i*2+1);
			a[i*2] = a[i*2+1] = 0;
		}
	}
	if(N%2 == 0){
		int t = a[N/2];
		if(t == 0){
			while(!q.empty()){
				if(!check[*q.begin()]) break;
				q.erase(q.begin());
			}
			t = *q.begin();
		}
		ans[N/2] = min(t,a[N]);
		check[ans[N/2]] = true;
		if(ans[N/2] == a[N]){
			copy(N);
			a[N] = 0;
		}
	}
	for(int i=N/2+1; i<=N; i++){
		if(a[i] != 0) ans[i] = a[i];
		else{
			for(auto &j : tmp[i]){
				if(check[j]) continue;
				ans[i] = j;
				break;
			}
		}
		check[ans[i]] = true;
	}
	for(int i=1; i<=N; i++) printf("%d ",ans[i]);

	return 0;
}

Compilation message

swap.cpp: In function 'int main()':
swap.cpp:25:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&N);
                ^
swap.cpp:27: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 Incorrect 3 ms 8468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 8468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 8468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 8468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 8468 KB Output isn't correct
2 Halted 0 ms 0 KB -