Submission #711648

#TimeUsernameProblemLanguageResultExecution timeMemory
711648PringSlagalica (COCI19_slagalica2)C++14
5 / 70
33 ms4232 KiB
#include <bits/stdc++.h> using namespace std; #define int long long typedef std::pair<int, int> pii; const int MXN = 100005; int n; struct P { bool l, r; int val; P() { l = false; r = false; val = 0; } }; vector<P> LL, RR, LR, RL; P first, last, br; bool state; bool check() { if (first.r && last.l && LR.size() != RL.size()) return false; if (first.r && !last.l && LR.size() != RL.size() - 1) return false; if (!first.r && last.l && LR.size() != RL.size() + 1) return false; if (!first.r && !last.l && LR.size() != RL.size()) return false; return true; } void OUT(vector<P> &v) { cout << v.back().val; state = v.back().r; v.pop_back(); } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); int type; cin >> n; for (int i = 0; i < n; i++) { cin >> type >> br.val; br.l = false, br.r = false; if (type == 3 || type == 4 || type == 8) br.l = true; if (type == 1 || type == 3 || type == 5) br.r = true; // cout << br.l << br.r << endl; if (type == 5 || type == 6) { first = br; } else if (type == 7 || type == 8) { last = br; } else (br.l ? (br.r ? RR : RL) : (br.r ? LR : LL)).push_back(br); } // cout << LL.size() << ' ' << LR.size() << ' ' << RL.size() << ' ' << RR.size() << endl; sort(LL.begin(), LL.end(), [](P a, P b) { return a.val < b.val; }); sort(LR.begin(), LR.end(), [](P a, P b) { return a.val < b.val; }); sort(RL.begin(), RL.end(), [](P a, P b) { return a.val < b.val; }); sort(RR.begin(), RR.end(), [](P a, P b) { return a.val < b.val; }); if (!check()) { cout << -1 << endl; return 0; } state = first.r; cout << first.val; for (int i = 1; i < n - 1; i++) { // cout << state << endl; cout << ' '; if (state) { // R if (RL.empty()) OUT(RR); else if (RR.empty()) OUT(RL); else if (LL.empty() && LR.empty()) OUT(RR); else OUT((RL.back().val < RR.back().val ? RR : RL)); } else { // L if (LL.empty()) OUT(LR); else if (LR.empty()) OUT(LL); else if (RL.empty() && RR.empty()) OUT(LL); else OUT((LL.back().val < LR.back().val ? LR : LL)); } } cout << ' ' << last.val << endl; 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...