Submission #711630

#TimeUsernameProblemLanguageResultExecution timeMemory
711630becaidoSlagalica (COCI19_slagalica2)C++17
70 / 70
51 ms3008 KiB
#pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx,popcnt,sse4,abm") #include <bits/stdc++.h> using namespace std; #ifdef WAIMAI #define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE) void dout() {cout << '\n';} template<typename T, typename...U> void dout(T t, U...u) {cout << t << (sizeof... (u) ? ", " : ""), dout (u...);} #else #define debug(...) 7122 #endif #define ll long long #define Waimai ios::sync_with_stdio(false), cin.tie(0) #define FOR(x,a,b) for (int x = a, I = b; x <= I; x++) #define pb emplace_back #define F first #define S second const int SIZE = 1e5 + 5; const int lt[8] = {-1, -1, 1, 1, 0, 0, -1, 1}; const int rt[8] = {1, -1, 1, -1, 1, -1, 0, 0}; int n; int sty, ety, sx, ex; priority_queue<int, vector<int>, greater<int>> pq[4]; void no() { cout << "-1\n"; exit(0); } void out(int i) { cout << pq[i].top() << ' '; pq[i].pop(); } void solve() { cin >> n; FOR (i, 1, n) { int ty, x; cin >> ty >> x; ty--; if (ty == 4 || ty == 5) { sty = ty == 4 ? 1 : -1; sx = x; } else if (ty == 6 || ty == 7) { ety = ty == 6 ? -1 : 1; ex = x; } else { pq[ty].push(x); } } if (sty == -1) { if (ety == -1) { if (pq[0].size() != pq[3].size() || (!pq[0].size() && pq[2].size())) no(); } if (ety == 1) { if (pq[0].size() != pq[3].size() + 1) no(); } } if (sty == 1) { if (ety == -1) { if (pq[0].size() + 1 != pq[3].size()) no(); } if (ety == 1) { if (pq[0].size() != pq[3].size() || (!pq[0].size() && pq[1].size())) no(); } } cout << sx << ' '; int cur = sty; while (pq[0].size() + pq[1].size() + pq[2].size() + pq[3].size()) { int mn[4]; FOR (i, 0, 3) mn[i] = pq[i].size() ? pq[i].top() : INT_MAX; if (cur == -1) { if (mn[1] < mn[0] || (ety == 1 && pq[3].size() == 0 && pq[1].size())) out(1); else out(0), cur = -cur; } else { if (mn[2] < mn[3] || (ety == -1 && pq[0].size() == 0 && pq[2].size())) out(2); else out(3), cur = -cur; } } cout << ex << '\n'; } int main() { Waimai; solve(); }
#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...