#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define crep(i,x,n) for(int i=x;i<n;i++)
#define drep(i,n) for(int i=n-1;i>=0;i--)
#define vec(...) vector<__VA_ARGS__>
#define _32bB6rn ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define nare {cout<<"-1\n"; exit(0);}
using namespace std;
typedef long long ll;
typedef long double ld;
using pii=pair<int,int>;
using vi=vector<int>;
int main(){
_32bB6rn;
int n;
cin>>n;
vec(vi) rbts(8);
rep(i,n){
int x,y;
cin>>x>>y;
x--;
rbts[x].pb(y);
}
rep(i,8){
sort(rbts[i].rbegin(),rbts[i].rend());
}
if(sz(rbts[4])>1
or sz(rbts[5])>1
or (sz(rbts[4]) and sz(rbts[5]))){
nare;
}
if(sz(rbts[6])>1
or sz(rbts[7])>1
or (sz(rbts[6]) and sz(rbts[7]))){
nare;
}
int open=sz(rbts[4])?4:5;
int close=sz(rbts[6])?6:7;
if(open==4){
if(close==6){
if(sz(rbts[3])!=sz(rbts[0])+1) nare;
}else{
if(sz(rbts[3])!=sz(rbts[0])) nare;
}
}else{
if(close==6){
if(sz(rbts[3])!=sz(rbts[0])) nare;
}else{
if(sz(rbts[3])+1!=sz(rbts[0])) nare;
}
}
vi pans;
pans.pb(rbts[open][0]);
int now=(open==4?1:0);
rep(i,n-2){
int x=1e9+1,y=1e9+1; // fix here
if(now){
if(sz(rbts[2])){
x=rbts[2].back();
}
if(sz(rbts[3])){
y=rbts[3].back();
}
if(min(x,y)==1e9+1) break;
if(x<y){
pans.pb(x);
rbts[2].pop_back();
}else{
pans.pb(y);
rbts[3].pop_back();
now^=1;
}
}else{
if(sz(rbts[1])){
x=rbts[1].back();
}
if(sz(rbts[0])){
y=rbts[0].back();
}
if(min(x,y)==1e9+1) break;
if(x<y){
pans.pb(x);
rbts[1].pop_back();
}else{
pans.pb(y);
rbts[0].pop_back();
now^=1;
}
}
}
assert(!sz(rbts[0]) and !sz(rbts[2]));
pans.pb(rbts[close][0]);
for(auto x : pans){
cout<<x<<" ";
}
//
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
2016 KB |
Output is correct |
2 |
Correct |
22 ms |
820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
1916 KB |
Output is correct |
2 |
Correct |
18 ms |
844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
840 KB |
Output is correct |
2 |
Incorrect |
26 ms |
1884 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
816 KB |
Output is correct |
2 |
Correct |
26 ms |
1816 KB |
Output is correct |
3 |
Incorrect |
27 ms |
1716 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
22 ms |
1736 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
1920 KB |
Output is correct |
2 |
Correct |
25 ms |
840 KB |
Output is correct |
3 |
Runtime error |
21 ms |
2052 KB |
Execution killed with signal 6 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
864 KB |
Output is correct |
2 |
Incorrect |
25 ms |
1912 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
22 ms |
2480 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
20 ms |
2252 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
30 ms |
2176 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
29 ms |
1968 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
24 ms |
2352 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |