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];
pair<int,int>ar[9];
signed main(){
ar[1]={1,1};
ar[2]={1,0};
ar[3]={0,1};
ar[4]={0,0};
ar[5]={-1,1};
ar[6]={-1,0};
ar[7]={1,-1};
ar[8]={0,-1};
cin>>n;
for(int i=1;i<=n;i++){
int typ;
int vl;
cin>>typ>>vl;
e[typ].push_back(vl);
}
for(int i=1;i<=8;i++){
sort(e[i].begin(),e[i].end());
reverse(e[i].begin(),e[i].end());
}
if(e[5].size()+e[6].size()!=1){
cout<<-1;return 0;
}
if(e[7].size()+e[8].size()!=1){
cout<<-1;return 0;
}vector<int>ans;
int lst;
if(e[5].size()){
lst=1;
ans.push_back(e[5][0]);
}else{
lst=0;
ans.push_back(e[6][0]);
}
for(int i=2;i<=n-1;i++){
/*cout<<i<<" ";
for(int j:ans){
cout<<j<<" ";
}cout<<endl;*/
if(lst==1){
if(e[3].size()+e[4].size()==0){cout<<-1;return 0;}
if(!e[4].size()){lst=1;ans.push_back(e[3].back());e[3].pop_back();continue;}
if(!e[3].size()){lst=0;ans.push_back(e[4].back());e[4].pop_back();continue;}
if(e[4].back()>e[3].back()){
lst=1;ans.push_back(e[3].back());e[3].pop_back();continue;
}else{
lst=0;ans.push_back(e[4].back());e[4].pop_back();continue;
}
}
if(e[1].size()+e[2].size()==0){cout<<-1;return 0;}
if(!e[2].size()){lst=1;ans.push_back(e[1].back());e[1].pop_back();continue;}
if(!e[1].size()){lst=0;ans.push_back(e[2].back());e[2].pop_back();continue;}
if(e[2].back()>e[1].back()){
lst=1;ans.push_back(e[1].back());e[1].pop_back();continue;
}else{
lst=0;ans.push_back(e[2].back());e[2].pop_back();continue;
}
}
int ed;
if(e[7].size()){
ed=1;
ans.push_back(e[7][0]);
}else{
ed=0;
ans.push_back(e[8][0]);
}
if(ed+lst!=1){
cout<<-1;return 0;
}
for(int i=0;i<ans.size();i++){
cout<<ans[i]<<" ";
}
}
Compilation message (stderr)
slagalica.cpp: In function 'int main()':
slagalica.cpp:88:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | for(int i=0;i<ans.size();i++){
| ~^~~~~~~~~~~
# | 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... |