Submission #496386

#TimeUsernameProblemLanguageResultExecution timeMemory
496386asandikciSlagalica (COCI19_slagalica2)C++17
70 / 70
63 ms6772 KiB
#include"iostream" #include"vector" // #include"queue" // #include"deque" #include"set" // #include"map" #include"algorithm" // #include"iomanip" // #include"cstring" // #include"cmath" // #include"bitset" #define int long long using namespace std; const int INF=1e9; const int maxn=1e5; int sbmp=0,ebmp=0; set<int> st[7]; bool check(int a,int b,int c,int d){ if(a<0 || b<0 || c<0 || d<0){return 0;} if(a==0 && b==0 && c==0 && d==0){return 1;} // cout << a << " " << b << " " << c <<" " << d << "\n"; if(sbmp==1 && ebmp==0){ // cout << "asd?"; if(a==d){ if(a==0 && b!=0){ return 0; } else{ return 1; } } return 0; } if(sbmp==0 && ebmp==1){ // cout << a << " " << b << " " << c <<" " << d << "\n"; if(a==d){ if(a==0 && c!=0){ return 0; } else{ return 1; } } return 0; } if(sbmp==1 && ebmp==1){ if(a==d-1){ return 1; } return 0; } if(sbmp==0 && ebmp==0){ // cout << a << " " << b << " " << c <<" " << d << "\n"; if(d==a-1){ return 1; } return 0; } // cout << "wha?"; return 0; } void solve(){ int n,a,b; cin >> n; pair<int,int> start,end; for(int i=0;i<n;i++){ cin >> a >> b; if(a<=4) st[a].insert(b); else if(a<=6) start={a,b}; else if(a<=8) end={a,b}; } // for(int i=0;i<5;i++){ // cout << st[i].size() << "\n"; // } if(start.first==5){ sbmp=1; } if(end.first==7){ ebmp=1; } vector<int> ans; // sbmp ve ebmp ve check fonksiyonunda öncelik karışması var // o anda olduğun yerden itibaren kontrol edeceksin for(int i=1;i<n-1;i++){ int mini=INF; int mininum=0; if(sbmp==0){ sbmp=1; if(check(st[1].size()-1,st[2].size(),st[3].size(),st[4].size())){ // cout << ".1\n"; if(mini>*st[1].begin()){ mininum=1; } mini = min(mini,*(st[1].begin())); } sbmp=0; } if(sbmp==0){ sbmp=0; if(check(st[1].size(),st[2].size()-1,st[3].size(),st[4].size())){ // cout << ".2\n"; if(mini>*st[2].begin()){ mininum=2; } mini = min(mini,*(st[2].begin())); } sbmp=0; } if(sbmp==1){ sbmp=1; if(check(st[1].size(),st[2].size(),st[3].size()-1,st[4].size())){ // cout << ".3\n"; if(mini>*st[3].begin()){ mininum=3; } mini = min(mini,*(st[3].begin())); } sbmp=1; } if(sbmp==1){ sbmp=0; // cout << st[4].size() << "--\n"; if(check(st[1].size(),st[2].size(),st[3].size(),st[4].size()-1)){ // cout << ".4\n"; if(mini>*st[4].begin()){ mininum=4; } mini = min(mini,*(st[4].begin())); } sbmp=1; } // cout << mininum << "<->" << mini << "\n\n"; ans.push_back(mini); if(mini==INF){cout << "-1";return;} if(mininum==1 || mininum==3){sbmp=1;} if(mininum==2 || mininum==4){sbmp=0;} st[mininum].erase(*(st[mininum].begin())); // cout << "\n"; } cout << start.second << " "; for(auto it : ans){ cout << it << " "; } cout << end.second << " "; // for(int i=0;i<5;i++){ // cout << st[i].size() << "\n"; // } } signed main(){ ios::sync_with_stdio(false); cin.tie(0); // freopen("","r",stdin);freopen("","w",stdout); int t=1; // cin >> t; for(int i=1;i<=t;i++){ // cout << "Case " << i << ":\n"; solve(); // cout <<"\n\n"; } }
#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...