Submission #940216

#TimeUsernameProblemLanguageResultExecution timeMemory
9402161075508020060209tcSlagalica (COCI19_slagalica2)C++14
40 / 70
54 ms3260 KiB
#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]; int lpl[2]; int rpl[2]; int ed; vector<int>ans; int ok(int typ){ if(ans.size()==n-2){return 1;} int rlft=0; if(ar[typ].second==ed){return 1;} for(int i=1;i<=4;i++){ int sz=e[i].size(); if(ar[i].first!=ar[typ].first){ continue; } if(i==typ){ sz--; } if(ar[i].second!=ed){ rlft+=sz; } } if(rlft==0){return 0;} return 1; } 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; } if(e[7].size()){ ed=1; }else{ ed=0; } 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++){ 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()&&ok(3)){ 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()&&ok(1)){ 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; } } 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; } if(ans.size()!=n){ cout<<-1;return 0; } for(int i=0;i<ans.size();i++){ cout<<ans[i]<<" "; } }

Compilation message (stderr)

slagalica.cpp: In function 'long long int ok(long long int)':
slagalica.cpp:14:14: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   14 | if(ans.size()==n-2){return 1;}
      |    ~~~~~~~~~~^~~~~
slagalica.cpp: In function 'int main()':
slagalica.cpp:120:14: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
  120 | if(ans.size()!=n){
      |    ~~~~~~~~~~^~~
slagalica.cpp:123: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]
  123 | for(int i=0;i<ans.size();i++){
      |             ~^~~~~~~~~~~
#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...