Submission #246197

# Submission time Handle Problem Language Result Execution time Memory
246197 2020-07-08T10:50:57 Z Halit Slagalica (COCI19_slagalica2) C++17
15 / 70
682 ms 10140 KB
#include <bits/stdc++.h>
using namespace std;

bool s = 1;
priority_queue<long long> heap[9];
vector<long long> ans;
map<long long, long long> val;
long long n,p,v,lst_3, lst_2;

int main(){
	cin >> n;
	for(int i = 1;i <= n;i++){
		cin >> p >> v;
		heap[p].push(-v);
		val[v] = p;
	}
	
	if(heap[5].size() + heap[6].size() != 1 || heap[7].size() + heap[8].size() != 1)
		goto CANNOT;
	
	if(heap[5].size()){
		s ^= 1;//   ->
		ans.push_back(-heap[5].top());
	} else{
		ans.push_back(-heap[6].top());
	}
		
	while(heap[1].size() + heap[4].size()){
		if(s == 1){
			
			if(heap[1].size() == 0)
				goto CANNOT;
			
			ans.push_back(-heap[1].top());
			heap[1].pop();
		} else{
			
			if(heap[4].size() == 0)
				goto CANNOT;
			
			ans.push_back(-heap[4].top());
			heap[4].pop();
		}
		s ^= 1;
	}
	
	if((s == 0? heap[8].size() == 0 : heap[7].size() == 0) )
		goto CANNOT;
		
	ans.push_back(-(heap[8].size() ? heap[8].top() : heap[7].top() ) );
	
	for(int i = 0, changes = 0;i < ans.size() - 1;i++){
		if(val[ans[i]] % 2 == 0 && heap[2].size() && ans[i] >= -heap[2].top()  ){
			ans.insert(ans.begin() + i + 1, -heap[2].top());
			heap[2].pop();
			changes++;
		} else if(val[ans[i]] % 2 == 1 && heap[3].size() && ans[i+1] >= -heap[3].top() ){
			ans.insert(ans.begin() + i + 1, -heap[3].top());
			heap[3].pop();
			changes++;
		}
	}
	
	for(int i = 0, changes = 0;i < ans.size() - 1;i++){
		if(val[ans[i]] % 2 == 0 && heap[2].size() ){
			ans.insert(ans.begin() + i + 1, -heap[2].top());
			heap[2].pop();
			changes++;
		} else if(val[ans[i]] % 2 == 1 && heap[3].size()){
			ans.insert(ans.begin() + i + 1, -heap[3].top());
			heap[3].pop();
			changes++;
		}
	}
	
	for(int i = 0;i < ans.size();i++){
		cout << ans[i] << " " ;
		
	}
	return 0;
	CANNOT: ;
	cout << -1;
}

Compilation message

slagalica.cpp: In function 'int main()':
slagalica.cpp:52:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0, changes = 0;i < ans.size() - 1;i++){
                             ~~^~~~~~~~~~~~~~~~
slagalica.cpp:64:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0, changes = 0;i < ans.size() - 1;i++){
                             ~~^~~~~~~~~~~~~~~~
slagalica.cpp:76:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0;i < ans.size();i++){
                ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 173 ms 8612 KB Output is correct
2 Correct 141 ms 8808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 166 ms 8548 KB Output is correct
2 Correct 130 ms 8164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 149 ms 8040 KB Output is correct
2 Incorrect 415 ms 8932 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 110 ms 6888 KB Output is correct
2 Incorrect 136 ms 8172 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 211 ms 8552 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 675 ms 8428 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 120 ms 7660 KB Output is correct
2 Incorrect 411 ms 8552 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 562 ms 9824 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 398 ms 8592 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 682 ms 10140 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 407 ms 8860 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 422 ms 8840 KB Output isn't correct
2 Halted 0 ms 0 KB -