# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
199747 | SamAnd | Slagalica (COCI19_slagalica2) | C++17 | 66 ms | 3576 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;
const int N = 100005, INF = 1000000009;
struct ban
{
int x;
ban(){}
ban(int x)
{
this->x = x;
}
};
bool operator<(const ban& a, const ban& b)
{
return a.x > b.x;
}
int n;
priority_queue<ban> q[10];
int s, f;
int u[10];
bool stg()
{
int z = s;
int q[10];
for (int i = 1; i <= 8; ++i)
q[i] = u[i];
if (z == 0)
q[2] = 0;
else
q[3] = 0;
if (z == 0 && q[1])
{
--q[1];
z = 1;
}
else if (z == 1 && q[4])
{
--q[4];
z = 0;
}
if (z == 0)
q[2] = 0;
else
q[3] = 0;
if (q[2] || q[3])
return false;
if (abs(q[1] - q[4]) >= 2)
return false;
if (q[1] == q[4] + 1)
{
if (z == 0)
{
--q[1];
z = 1;
}
}
if (q[4] == q[1] + 1)
{
if (z == 1)
{
--q[4];
z = 0;
}
}
if (q[1] == q[4])
q[1] = q[4] = 0;
else
return false;
if (f && z)
return false;
if (!f && !z)
return false;
return true;
}
int ans[N];
int main()
{
scanf("%d", &n);
for (int i = 1; i <= n; ++i)
{
int ty, x;
scanf("%d%d", &ty, &x);
q[ty].push(ban(x));
}
if (!q[5].empty())
{
s = 1;
ans[1] = q[5].top().x;
q[5].pop();
}
else
{
s = 0;
ans[1] = q[6].top().x;
q[6].pop();
}
if (!q[7].empty())
{
f = 1;
ans[n] = q[7].top().x;
q[7].pop();
}
else
{
f = 0;
ans[n] = q[8].top().x;
q[8].pop();
}
for (int i = 1; i <= 8; ++i)
{
u[i] = q[i].size();
}
if (!stg())
{
printf("-1\n");
return 0;
}
for (int ii = 2; ii < n; ++ii)
{
int minu = INF;
for (int i = 1; i <= 8; ++i)
{
if (!q[i].empty())
{
if (i == 1 && s == 1)
continue;
if (i == 2 && s == 1)
continue;
if (i == 3 && s == 0)
continue;
if (i == 4 && s == 0)
continue;
--u[i];
int ss = s;
if (i == 1)
s = 1;
if (i == 2)
s = 0;
if (i == 3)
s = 1;
if (i == 4)
s = 0;
if (stg())
{
minu = min(minu, q[i].top().x);
}
++u[i];
s = ss;
}
}
for (int i = 1; i <= 8; ++i)
{
if (!q[i].empty())
{
if (i == 1 && s == 1)
continue;
if (i == 2 && s == 1)
continue;
if (i == 3 && s == 0)
continue;
if (i == 4 && s == 0)
continue;
if (q[i].top().x == minu)
{
ans[ii] = q[i].top().x;
q[i].pop();
--u[i];
if (i == 1)
s = 1;
if (i == 2)
s = 0;
if (i == 3)
s = 1;
if (i == 4)
s = 0;
break;
}
}
}
}
for (int i = 1; i <= n; ++i)
printf("%d ", ans[i]);
printf("\n");
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... |