답안 #199002

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
199002 2020-01-28T15:41:55 Z TadijaSebez Swap (BOI16_swap) C++11
0 / 100
5 ms 268 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
const int inf=1e9+7;
pair<int,int> min(pair<int,int> a,pair<int,int> b){return a<b?a:b;}
vector<int> mrg(vector<int> a,vector<int> b){
	while(b.size())a.pb(b.back()),b.pop_back();
	return a;
}
int main(){
	int n;
	scanf("%i",&n);
	vector<vector<int>> a(n*2+5,vector<int>(0));
	vector<bool> was(n+1,0);
	for(int i=1,j;i<=n;i++)scanf("%i",&j),a[i].pb(j);
	for(int i=n+1;i<a.size();i++)a[i].pb(inf);
	for(int i=1;i<=n;i++){
		sort(a[i].rbegin(),a[i].rend());
		while(was[a[i].back()])a[i].pop_back();
		int ch=i<<1|1;
		if(a[i<<1][0]<a[i<<1|1][0])ch=i<<1;
		if(a[ch][0]<a[i].back()){
			if(ch&1){
				vector<int> tmp=mrg(a[i],a[ch^1]);
				a[i]=a[ch];
				a[ch]=a[ch^1]=tmp;
			}else{
				swap(a[i],a[ch]);
			}
		}else{
			int my=a[i].back();
			a[i].clear();
			a[i].pb(my);
		}
		was[a[i][0]]=1;
		printf("%i ",a[i][0]);
	}
	return 0;
}

Compilation message

swap.cpp: In function 'int main()':
swap.cpp:17:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=n+1;i<a.size();i++)a[i].pb(inf);
                ~^~~~~~~~~
swap.cpp:13:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i",&n);
  ~~~~~^~~~~~~~~
swap.cpp:16:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1,j;i<=n;i++)scanf("%i",&j),a[i].pb(j);
                         ~~~~~~~~~~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Incorrect 5 ms 268 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Incorrect 5 ms 268 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Incorrect 5 ms 268 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Incorrect 5 ms 268 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Incorrect 5 ms 268 KB Output isn't correct
4 Halted 0 ms 0 KB -