This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |