답안 #246151

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
246151 2020-07-08T10:05:55 Z Halit Slagalica (COCI19_slagalica2) C++17
35 / 70
1000 ms 10336 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;

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;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();
		} else if(val[ans[i]] % 2 == 1 && heap[3].size()){
			ans.insert(ans.begin() + i + 1, -heap[3].top());
			heap[3].pop();
		}
	}
	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:53:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0;i < ans.size() - 1;i++){
                ~~^~~~~~~~~~~~~~~~
slagalica.cpp:62:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0;i < ans.size();i++){
                ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 169 ms 9056 KB Output is correct
2 Correct 158 ms 9300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 164 ms 8796 KB Output is correct
2 Correct 146 ms 8680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 136 ms 8548 KB Output is correct
2 Correct 170 ms 9352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 127 ms 7300 KB Output is correct
2 Correct 145 ms 8708 KB Output is correct
3 Correct 196 ms 10336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 169 ms 9340 KB Output is correct
2 Correct 139 ms 7904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 156 ms 8808 KB Output is correct
2 Correct 140 ms 7784 KB Output is correct
3 Correct 191 ms 9932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 139 ms 8040 KB Output is correct
2 Incorrect 659 ms 9172 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1088 ms 9620 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 634 ms 8824 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 990 ms 10244 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 688 ms 8976 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 677 ms 8900 KB Output isn't correct
2 Halted 0 ms 0 KB -