/*
ID: antwand1
TASK: barn1
LANG: C++
*/
#include <bits/stdc++.h>
#define ll long long
#define du long double
#define F first
#define S second
using namespace std;
const int N=1e5+1;
string s;
deque<int> v[9];
int n;
bool bc(int i,int a)
{
if(i==n){
if(a==0){
if(v[7].empty()==0){
s+=v[7].front()+'0';
return 1;
}
else return 0;
}
else{
if(v[8].empty()==0){
s+=v[8].front()+'0';
return 1;
}
else return 0;
}
}
bool ret=0;
if(a==0){
if(v[1].empty()&&v[2].empty())return 0;
if(v[1].empty()){
int q=v[2][0];
v[2].pop_front();
ret=bc(i+1,0);
v[2].push_front(q);
if(ret)s+=q+'0';
return ret;
}
else{
if(v[2].empty()){
int q=v[1][0];
v[1].pop_front();
ret=bc(i+1,1);
v[1].push_front(q);
if(ret)s+=q+'0';
return ret;
}
else{
if(v[1][0]<v[2][0]){
int q=v[1][0];
v[1].pop_front();
ret=bc(i+1,1);
v[1].push_front(q);
if(ret)s+=q+'0';
if(ret)return ret;
q=v[2][0];
v[2].pop_front();
ret=bc(i+1,0);
v[2].push_front(q);
if(ret)s+=q+'0';
return ret;
}
else{
int q=v[2][0];
v[2].pop_front();
ret=bc(i+1,0);
v[2].push_front(q);
if(ret)s+=q+'0';
if(ret)return ret;
q=v[1][0];
v[1].pop_front();
ret=bc(i+1,1);
v[1].push_front(q);
if(ret)s+=q+'0';
return ret;
}
}
}
}
else{
if(v[3].empty()&&v[4].empty())return 0;
if(v[3].empty()){
int q=v[4][0];
v[4].pop_front();
ret=bc(i+1,0);
v[4].push_front(q);
if(ret)s+=q+'0';
return ret;
}
else{
if(v[3].empty()){
int q=v[3][0];
v[3].pop_front();
ret=bc(i+1,1);
v[3].push_front(q);
if(ret)s+=q+'0';
return ret;
}
else{
if(v[3][0]<v[4][0]){
int q=v[1][0];
v[3].pop_front();
ret=bc(i+1,1);
v[3].push_front(q);
if(ret)s+=q+'0';
if(ret)return ret;
q=v[4][0];
v[4].pop_front();
ret=bc(i+1,0);
v[4].push_front(q);
if(ret)s+=q+'0';
return ret;
}
else{
int q=v[4][0];
v[4].pop_front();
ret=bc(i+1,0);
v[4].push_front(q);
if(ret)s+=q+'0';
if(ret)return ret;
q=v[3][0];
v[3].pop_front();
ret=bc(i+1,1);
v[3].push_front(q);
if(ret)s+=q+'0';
return ret;
}
}
}
/********dddd*/
}
}
main()
{
//freopen("barn1.in","r",stdin);freopen("barn1.out","w",stdout);
cin>>n;
for(int i=1;i<=n;i++){
int x,a;
cin>>x>>a;
v[x].push_back(a);
}
for(int i=1;i<=8;i++)sort(v[i].begin(),v[i].end());
if(v[5].empty()==0){
if(bc(2,1)){
s+=v[5][0]+'0';
reverse(s.begin(),s.end());
for(int i=0;i<n;i++){
cout<<s[i]<<" ";
}
cout<<endl;
}
else cout<<-1<<endl;
}
else if(v[6].empty()==0){
if(bc(2,0)){
s+=v[6][0]+'0';
reverse(s.begin(),s.end());
for(int i=0;i<n;i++){
cout<<s[i]<<" ";
}
cout<<endl;
}
else cout<<-1<<endl;
}
}
Compilation message
slagalica.cpp:140:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
140 | main()
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
75 ms |
7936 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
69 ms |
7532 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
4844 KB |
Output is correct |
2 |
Execution timed out |
1084 ms |
5100 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
4076 KB |
Output is correct |
2 |
Incorrect |
68 ms |
7404 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1090 ms |
4588 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
70 ms |
7532 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
73 ms |
14012 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
82 ms |
8812 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
74 ms |
7404 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
85 ms |
8812 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
67 ms |
7276 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
69 ms |
7456 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |