#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 vll;
typedef unsigned __int128 uvll;
ll _i=0;
#define ffn(x) _i=x
#define llll pair<ll , ll>
#define stitr set<ll>::iterator
#define fora(y,x) for(ll y=_i;x>y;y++)
#define pb push_back
#define pf push_front
#define debu cout << "hello\n"
#define fi first
#define sec second
#define all(a) a.begin() , a.end()
const ll limit = 1e13 + 7;
const ll ous=1e5 + 5;
const ll dx[4] = {0 , -1 , 1 , 0} , dy[4] = {1,0,0,-1};
void solve(){
ll n;cin >> n;
ll b = 0 , h = 0;
ll rs = 0 , rsb = 0 , le = 0 , lb = 0;
set<ll> st[4];
fora(i,n){
ll x , y;cin >> x >> y;
if(x == 1){
st[x-1].insert(y);
b+=2;
}
if(x == 2){
b++;h++;
st[x-1].insert(y);
}
if(x == 3){
b++;h++;
st[x-1].insert(y);
}
if(x == 4){
h+=2;
st[x-1].insert(y);
}
if(x == 5){
rs = y;
rsb = 1;
b++;
}
if(x == 6){
rs = y,
rsb = 0;
h++;
}
if(x == 7){
le = y;
lb = 1;
b++;
}
if(x == 8){
le = y;
lb = 0;
h++;
}
}
//cout << h << " " << b << "\n";
if(h != b){
cout << -1 << "\n";
return;
}
cout << rs << " ";
ll hob = rsb;
ll k = st[0].size() + st[1].size() + st[2].size() + st[3].size();
ll l = st[0].size() + st[1].size(), r = st[2].size() + st[3].size();
ll ret = 2;
while(k){
if(hob == 0){
if(r == 0 && l!=1){
cout << *st[1].begin() << " ";
st[1].erase(st[1].begin());
}
else{
if(!st[1].empty() && (st[0].empty() || *st[0].begin() > *st[1].begin())){
cout << *st[1].begin() << " ";
st[1].erase(st[1].begin());
}
else{
hob = 1;
cout << *st[0].begin() << " ";
st[0].erase(st[0].begin());
}
}
}
else{
if(l == 0 && r!=1){
cout << *st[2].begin() << " ";
st[2].erase(st[2].begin());
}
else{
if(!st[2].empty() && (st[3].empty() || *st[3].begin() > *st[2].begin())){
cout << *st[2].begin() << " ";
st[2].erase(st[2].begin());
}
else{
hob = 0;
cout << *st[3].begin() << " ";
st[3].erase(st[3].begin());
}
}
}
l = st[0].size() + st[1].size(); r = st[2].size() + st[3].size();
k = l+r;
}
cout << le ;
return;/**/
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
ll t=1;
//cin >> t;
while(t--){
solve();
}
return 0;
}
Compilation message
slagalica.cpp: In function 'void solve()':
slagalica.cpp:24:36: warning: variable 'lb' set but not used [-Wunused-but-set-variable]
24 | ll rs = 0 , rsb = 0 , le = 0 , lb = 0;
| ^~
slagalica.cpp:74:8: warning: unused variable 'ret' [-Wunused-variable]
74 | ll ret = 2;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 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 |
Execution timed out |
1065 ms |
204 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
5188 KB |
Output is correct |
2 |
Correct |
43 ms |
4708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
4948 KB |
Output is correct |
2 |
Correct |
43 ms |
4352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
4864 KB |
Output is correct |
2 |
Execution timed out |
1086 ms |
5264 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
48 ms |
4304 KB |
Output is correct |
2 |
Correct |
52 ms |
4920 KB |
Output is correct |
3 |
Execution timed out |
1091 ms |
5592 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1092 ms |
4804 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
5016 KB |
Output is correct |
2 |
Correct |
39 ms |
4524 KB |
Output is correct |
3 |
Execution timed out |
1086 ms |
5312 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
4292 KB |
Output is correct |
2 |
Execution timed out |
1081 ms |
5000 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1084 ms |
5824 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1085 ms |
4944 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1089 ms |
5756 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1069 ms |
4936 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1084 ms |
4932 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |