# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
444696 | penguinhacker | Slagalica (COCI19_slagalica2) | C++14 | 50 ms | 3032 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |