Submission #199747

# Submission time Handle Problem Language Result Execution time Memory
199747 2020-02-03T06:16:25 Z SamAnd Slagalica (COCI19_slagalica2) C++17
70 / 70
66 ms 3576 KB
#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

slagalica.cpp: In function 'int main()':
slagalica.cpp:83:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
slagalica.cpp:87:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &ty, &x);
         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 3084 KB Output is correct
2 Correct 32 ms 1984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 2868 KB Output is correct
2 Correct 32 ms 1908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 2036 KB Output is correct
2 Correct 57 ms 3188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 1952 KB Output is correct
2 Correct 48 ms 3056 KB Output is correct
3 Correct 60 ms 3392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 3060 KB Output is correct
2 Correct 32 ms 2040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 3056 KB Output is correct
2 Correct 31 ms 1908 KB Output is correct
3 Correct 57 ms 3316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 2040 KB Output is correct
2 Correct 51 ms 2940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 61 ms 3576 KB Output is correct
2 Correct 31 ms 1832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 2936 KB Output is correct
2 Correct 30 ms 1844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 3540 KB Output is correct
2 Correct 45 ms 1912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 3080 KB Output is correct
2 Correct 32 ms 1912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 3020 KB Output is correct
2 Correct 32 ms 1912 KB Output is correct