Submission #199003

# Submission time Handle Problem Language Result Execution time Memory
199003 2020-01-28T15:43:34 Z TadijaSebez Swap (BOI16_swap) C++11
0 / 100
6 ms 504 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(),assert(a[i].size());
		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);
                         ~~~~~~~~~~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 6 ms 256 KB Output is correct
3 Runtime error 6 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 6 ms 256 KB Output is correct
3 Runtime error 6 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 6 ms 256 KB Output is correct
3 Runtime error 6 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 6 ms 256 KB Output is correct
3 Runtime error 6 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 6 ms 256 KB Output is correct
3 Runtime error 6 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -