# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
940274 | 1075508020060209tc | Slagalica (COCI19_slagalica2) | C++14 | 0 ms | 0 KiB |
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;
//#define int long long
#define X first
#define Y second
int n;
vector<int>e[9];
int cntl[3];
int cntr[3];
int ar[9][2]={
{0,0},
{1,1},
{1,0},
{0,1},
{0,0},
{2,1},
{2,0},
{1,2},
{0,2}
};
int ca;int cb;
int ok(int typ){
ca=ar[typ][0];
if(ca==0){
if()
}
return 1;
}
int ans[200005];
signed main(){
cin>>n;
for(int i=1;i<=n;i++){
int typ;
int vl;
cin>>typ>>vl;
e[typ].push_back(vl);
if(typ>4){continue;}
cntl[ar[typ][0]]++;
cntr[ar[typ][1]]++;
}
int lst;int ed;
if(e[7].size()){
ed=1;cb=-1;
ans[n]=e[7][0];
}else{
ed=0;cb=1;
ans[n]=e[8][0];
}
if(e[5].size()){
lst=1;ca=-1;
ans[1]=e[5][0];
if(!ok(5)){
cout<<-1;return 0;
}
}else{
lst=0;ca=1;
ans[1]=e[6][0];
if(!ok(6)){
cout<<-1;return 0;
}
}
for(int i=2;i<=n-1;i++){
int ret=2e9;
for(int typ=1;typ<=4;typ++){
if(ar[typ][0]==lst){continue;}
if(e[typ].size()==0){continue;}
cntl[ar[typ][0]]--;cntr[ar[typ][1]]--;
if(ok(typ)&&(ret==2e9||e[ret].back()>e[typ].back())){
ret=typ;
}
cntl[ar[typ][0]]++;cntr[ar[typ][1]]++;
}
if(ret>4){
cout<<-1;return 0;
}
cout<<ret<<"\n";
cntl[ar[ret][0]]--;cntr[ar[ret][1]]--;
ans[i]=e[ret].back();
e[ret].pop_back();
lst=ar[ret][1];
}
for(int i=1;i<=n;i++){
cout<<ans[i]<<" ";
}
}