Submission #444686

#TimeUsernameProblemLanguageResultExecution timeMemory
444686penguinhackerSlagalica (COCI19_slagalica2)C++14
15 / 70
36 ms3004 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ar array const int mxN=1e5; int n; ar<int, 2> a[mxN]; vector<ar<int, 2>> first, last; // 0 is sticking out deque<int> q[2][2]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i=0; i<n; ++i) { int x, y; cin >> x >> y; if (x==5||x==6) first.push_back({y, x-5}); else if (x==7||x==8) last.push_back({y, (x-7)^1}); else if (x==3||x==4) q[0][x==4].push_back(y); else q[1][x==2].push_back(y); } if (first.size()!=1||last.size()!=1) { cout << -1; return 0; } for (int i : {0, 1}) for (int j : {0, 1}) sort(q[i][j].begin(), q[i][j].end()); vector<int> ans={first[0][0]}; int cur=first[0][1]; for (int i=1; i<n-1; ++i) { if (q[cur][0].empty()&&q[cur][1].empty()) { cout << -1; return 0; } int t; if (q[cur][0].empty()^q[cur][1].empty()) t=q[cur][0].empty(); else if (q[0][last[0][1]].size()+q[1][last[0][1]].size()>1) t=q[cur][1][0]<q[cur][0][0]; else t=last[0][1]^1; assert(q[cur][t].size()); ans.push_back(q[cur][t][0]); q[cur][t].pop_front(); cur=t; } if (cur!=last[0][1]) { cout << -1; } else { for (int i : ans) cout << i << " "; cout << last[0][0]; } 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...