Submission #497222

#TimeUsernameProblemLanguageResultExecution timeMemory
497222inksamuraiSlagalica (COCI19_slagalica2)C++17
70 / 70
38 ms2740 KiB
#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()); } int open=sz(rbts[4])?4:5; int close=sz(rbts[6])?6:7; 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; } 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; } } vec(pii) pans; pans.pb({rbts[open][0],open}); int now=(open==4?1:0); while(sz(rbts[3]) or sz(rbts[0])){ if(now){ if(!sz(rbts[3])) nare; while(sz(rbts[2]) and rbts[2].back()<rbts[3].back()){ pans.pb({rbts[2].back(),2}); rbts[2].pop_back(); } pans.pb({rbts[3].back(),3}); rbts[3].pop_back(); }else{ if(!sz(rbts[0])) nare; while(sz(rbts[1]) and rbts[1].back()<rbts[0].back()){ pans.pb({rbts[1].back(),1}); rbts[1].pop_back(); } pans.pb({rbts[0].back(),0}); rbts[0].pop_back(); } now^=1; } auto affine=[&](int id,vi rbt){ vec(pii) delay; while(sz(pans)>id+1){ delay.pb(pans.back()); pans.pop_back(); } while(sz(rbt)){ pans.pb({rbt.back(),11}); rbt.pop_back(); } while(sz(delay)){ pans.pb(delay.back()); delay.pop_back(); } }; if(sz(rbts[2])){ int id=-1; rep(i,sz(pans)){ if(pans[i].se==4 or pans[i].se==0 or pans[i].se==2){ id=i; } } if(id==-1) nare; affine(id,rbts[2]); } if(sz(rbts[1])){ int id=-1; rep(i,sz(pans)){ if(pans[i].se==5 or pans[i].se==3 or pans[i].se==1){ id=i; } } if(id==-1) nare; affine(id,rbts[1]); } pans.pb({rbts[close][0],close}); for(auto p : pans){ cout<<p.fi<<" "; } // return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...