Submission #27059

# Submission time Handle Problem Language Result Execution time Memory
27059 2017-07-09T06:36:00 Z 서규호(#1119) Swap (BOI16_swap) C++
Compilation error
0 ms 0 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 'void copy(int)':
swap.cpp:20:6: warning: 'auto' changes meaning in C++11; please remove it [-Wc++0x-compat]
  for(auto &i : q) tmp[x].pb(i);
      ^
swap.cpp:20:12: error: ISO C++ forbids declaration of 'i' with no type [-fpermissive]
  for(auto &i : q) tmp[x].pb(i);
            ^
swap.cpp:20:16: warning: range-based 'for' loops only available with -std=c++11 or -std=gnu++11
  for(auto &i : q) tmp[x].pb(i);
                ^
swap.cpp: In function 'int main()':
swap.cpp:69:8: warning: 'auto' changes meaning in C++11; please remove it [-Wc++0x-compat]
    for(auto &j : tmp[i]){
        ^
swap.cpp:69:14: error: ISO C++ forbids declaration of 'j' with no type [-fpermissive]
    for(auto &j : tmp[i]){
              ^
swap.cpp:69:18: warning: range-based 'for' loops only available with -std=c++11 or -std=gnu++11
    for(auto &j : tmp[i]){
                  ^
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]);
                    ^