# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
444696 | 2021-07-14T21:23:13 Z | penguinhacker | Slagalica (COCI19_slagalica2) | C++14 | 50 ms | 3032 KB |
#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], first, last; priority_queue<int, vector<int>, greater<int>> same[2], dif[2]; bool ck(int sub, int at) { if (sub!=-1&&dif[sub].empty()) return 0; int d[2]={(int)dif[0].size(), (int)dif[1].size()}; if (sub!=-1) --d[sub]; if (!d[0]&&!d[1]&&same[at^1].size()) return 0; if (at!=last[1]) { if (!d[at]) return 0; --d[at]; at^=1; } return d[0]==d[1]; } void init() { cin >> n; for (int i=0; i<n; ++i) { int t, a; cin >> t >> a; if (t==1) dif[1].push(a); else if (t==2) same[1].push(a); else if (t==3) same[0].push(a); else if (t==4) dif[0].push(a); else if (t==5||t==6) { if (first[0]) { cout << -1; exit(0); } first={a, t==6}; } else { if (last[0]) { cout << -1; exit(0); } last={a, t==7}; } } if (!first[0]||!last[0]||!ck(-1, first[1])) { cout << -1; exit(0); } } int main() { ios::sync_with_stdio(0); cin.tie(0); init(); cout << first[0] << " "; int cur=first[1]; for (int i=1; i<n-1; ++i) { bool ok[2]={same[cur].size(), ck(cur, cur^1)}; assert(ok[0]||ok[1]); if (ok[0]&&!ok[1]||ok[0]&&ok[1]&&same[cur].top()<dif[cur].top()) { cout << same[cur].top() << " "; same[cur].pop(); } else { cout << dif[cur].top() << " "; dif[cur].pop(); cur^=1; } } assert(same[0].empty()&&same[1].empty()&&dif[0].empty()&&dif[1].empty()&&cur==last[1]); cout << last[0]; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 0 ms | 204 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 45 ms | 2684 KB | Output is correct |
2 | Correct | 21 ms | 1740 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 39 ms | 2460 KB | Output is correct |
2 | Correct | 20 ms | 1836 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 22 ms | 1868 KB | Output is correct |
2 | Correct | 42 ms | 2640 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 19 ms | 1784 KB | Output is correct |
2 | Correct | 41 ms | 2536 KB | Output is correct |
3 | Correct | 50 ms | 2720 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 39 ms | 2684 KB | Output is correct |
2 | Correct | 21 ms | 1872 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 38 ms | 2572 KB | Output is correct |
2 | Correct | 22 ms | 1844 KB | Output is correct |
3 | Correct | 50 ms | 2876 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 20 ms | 1860 KB | Output is correct |
2 | Correct | 41 ms | 2532 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 46 ms | 2888 KB | Output is correct |
2 | Correct | 20 ms | 1756 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 38 ms | 2504 KB | Output is correct |
2 | Correct | 20 ms | 1772 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 46 ms | 3032 KB | Output is correct |
2 | Correct | 22 ms | 1964 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 37 ms | 2668 KB | Output is correct |
2 | Correct | 21 ms | 1872 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 38 ms | 2644 KB | Output is correct |
2 | Correct | 21 ms | 1860 KB | Output is correct |