답안 #484206

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
484206 2021-11-02T12:44:59 Z starplat Slagalica (COCI19_slagalica2) C++14
70 / 70
41 ms 2220 KB
#include <bits/stdc++.h>
#define xoxo {cout<<-1<<endl;return 0;}
using namespace std;
int n,id,x;
char l,r;
deque<int> q;
vector<int> a[10];
int max(int x,int y)
{
	return (a[x].size()>a[y].size()?a[x].size():a[y].size());
}
int main()
{
	cin.tie(0)->sync_with_stdio(0);
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>id>>x;
		a[id].push_back(x);
	}
	for (int i=1;i<=8;i++) sort(a[i].begin(),a[i].end());
	for (int i=1;i<=8;i++) reverse(a[i].begin(),a[i].end());
	if (max(5,6)>1||max(5,6)==0||max(7,8)>1||max(7,8)==0) xoxo
	if (a[5].size()^a[6].size()==0||a[7].size()^a[8].size()==0) xoxo
	l=(a[5].size()?'>':'<');
	r=(a[7].size()?'<':'>');
	n-=2;
	q.push_back(a[5].size()?a[5].back():a[6].back());
	while (n){
		int x=q.size();
		if (l=='>'){
			while (a[3].size()&&a[4].size()&&a[3].back()<=a[4].back()||a[4].size()==1&&a[1].size()==0&&a[3].size()){
				q.push_back(a[3].back()),a[3].pop_back();
				n--,l='>';
			}
			if (a[4].size()){
				q.push_back(a[4].back()),a[4].pop_back(),n--,l='<';
			} 
			else if (a[3].size()) {
				q.push_back(a[3].back()),a[3].pop_back(),n--,l='>';
			}
		}
		else {
			while (a[1].size()&&a[2].size()&&a[2].back()<=a[1].back()||a[1].size()==1&&a[4].size()==0&&a[2].size()){
				q.push_back(a[2].back()),a[2].pop_back();
				n--,l='<';
			}
			if (a[1].size()) {
				q.push_back(a[1].back()),a[1].pop_back(),n--,l='>';
			}
			else if (a[2].size()){
				q.push_back(a[2].back()),a[2].pop_back(),n--,l='<';
			}
		}
		if (x==q.size()) break;
	}
	if (n||l!=r) xoxo
	while (!q.empty()) cout<<q.front()<<" ",q.pop_front();
	cout<<(r=='<'?a[7].back():a[8].back())<<endl;
}
/*
7
5 1
3 10
3 9
4 8
1 7
3 6
8 5
1 6 8 7 9 10 5
[> >> >< <> >> >> >]
*/

Compilation message

slagalica.cpp: In function 'int main()':
slagalica.cpp:23:29: warning: suggest parentheses around comparison in operand of '^' [-Wparentheses]
   23 |  if (a[5].size()^a[6].size()==0||a[7].size()^a[8].size()==0) xoxo
      |                  ~~~~~~~~~~~^~~
slagalica.cpp:23:57: warning: suggest parentheses around comparison in operand of '^' [-Wparentheses]
   23 |  if (a[5].size()^a[6].size()==0||a[7].size()^a[8].size()==0) xoxo
      |                                              ~~~~~~~~~~~^~~
slagalica.cpp:31:35: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   31 |    while (a[3].size()&&a[4].size()&&a[3].back()<=a[4].back()||a[4].size()==1&&a[1].size()==0&&a[3].size()){
      |           ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
slagalica.cpp:43:35: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   43 |    while (a[1].size()&&a[2].size()&&a[2].back()<=a[1].back()||a[1].size()==1&&a[4].size()==0&&a[2].size()){
      |           ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
slagalica.cpp:54:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |   if (x==q.size()) break;
      |       ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 1772 KB Output is correct
2 Correct 20 ms 1076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 1816 KB Output is correct
2 Correct 18 ms 944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 840 KB Output is correct
2 Correct 36 ms 1804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 788 KB Output is correct
2 Correct 26 ms 1808 KB Output is correct
3 Correct 28 ms 1964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 1832 KB Output is correct
2 Correct 19 ms 888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 1700 KB Output is correct
2 Correct 24 ms 796 KB Output is correct
3 Correct 41 ms 1920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 1028 KB Output is correct
2 Correct 24 ms 1776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 2100 KB Output is correct
2 Correct 19 ms 1928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 1716 KB Output is correct
2 Correct 25 ms 1948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 1988 KB Output is correct
2 Correct 22 ms 2116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 1732 KB Output is correct
2 Correct 19 ms 2124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 1812 KB Output is correct
2 Correct 24 ms 2220 KB Output is correct