Submission #771228

# Submission time Handle Problem Language Result Execution time Memory
771228 2023-07-02T16:32:50 Z SamAnd Monster Game (JOI21_monster) C++17
91 / 100
101 ms 536 KB
#include "monster.h"
#include <algorithm>
#include <vector>
using namespace std;
#define sz(x) ((int)(x).size())

bool stg(int n, int i)
{
    int q = 0;
    for (int j = 0; j < n; ++j)
    {
        if (i == j)
            continue;
        if (Query(i, j))
            ++q;
    }
    return (q == 1);
}

void ezr(int n, vector<int>& v, int i, int j)
{
    if (i == 0)
    {
        for (int k = i; k <= j; ++k)
        {
            if (!stg(n, v[k]))
            {
                for (int t = k + 1; t <= j; ++t)
                    swap(v[t], v[t - 1]);
                break;
            }
        }
        if (Query(v[2], v[1]))
            swap(v[0], v[1]);
    }
    else
    {
        for (int k = i; k <= j; ++k)
        {
            if (!Query(v[k], v[i - 1]))
            {
                for (int t = k - 1; t >= i; --t)
                    swap(v[t], v[t + 1]);
                break;
            }
        }
        if (Query(v[i + 1], v[i]))
            swap(v[i + 1], v[i + 2]);
    }
}

vector<int> Solve(int n)
{
    vector<int> v;
    v.push_back(0);
    for (int i = 1; i < n; ++i)
    {
        int l = 0, r = sz(v) - 1;
        int u = -1;
        while (l <= r)
        {
            int m = (l + r) / 2;
            if (Query(i, v[m]))
            {
                u = m;
                l = m + 1;
            }
            else
                r = m - 1;
        }
        vector<int> nv;
        if (u == -1)
            nv.push_back(i);
        for (int j = 0; j < sz(v); ++j)
        {
            nv.push_back(v[j]);
            if (u == j)
                nv.push_back(i);
        }
        v = nv;
    }

    for (int i = 0; i < n - 1; ++i)
    {
        if (i + 1 == n - 1)
        {
            if (!Query(v[i], v[i + 1]))
                swap(v[i], v[i + 1]);
        }
        else
        {
            if (Query(v[i], v[i + 2]))
            {
                int j = i + 2;
                while (j + 1 < n && Query(v[i], v[j + 1]))
                    ++j;
                if ((j - i + 1) == 3)
                {
                    ezr(n, v, i, j);
                    i = j;
                    continue;
                }
                int ty = 1;
                if (i == 0)
                {
                    if (stg(n, v[j]))
                        ty = 0;
                }
                else
                {
                    if (!Query(v[j], v[i - 1]))
                        ty = 0;
                }
                if (ty == 0)
                    reverse(v.begin() + i, v.begin() + j + 1);
                else
                    reverse(v.begin() + i, v.begin() + j);
                i = j;
            }
            else
            {
                int j = i + 2;
                while (j + 1 < n && !Query(v[i], v[j + 1]))
                    ++j;
                ++j;
                if ((j - i + 1) == 3)
                {
                    ezr(n, v, i, j);
                    i = j;
                    continue;
                }
                int ty = 1;
                if (i == 0)
                {
                    if (stg(n, v[j]))
                        ty = 0;
                }
                else
                {
                    if (!Query(v[i], v[i - 1]))
                        ty = 0;
                }
                if (ty == 0)
                    reverse(v.begin() + i + 1, v.begin() + j + 1);
                else
                {
                    swap(v[i], v[i + 1]);
                    reverse(v.begin() + i + 2, v.begin() + j + 1);
                }
                i = j;
            }
        }
    }

    vector<int> ans(n);
    for (int i = 0; i < n; ++i)
        ans[v[i]] = i;
    return ans;
}

/*
5
1 2 3 4 0
*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 0 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 0 ms 208 KB Output is correct
16 Correct 17 ms 208 KB Output is correct
17 Correct 15 ms 304 KB Output is correct
18 Correct 7 ms 208 KB Output is correct
19 Correct 14 ms 300 KB Output is correct
20 Correct 14 ms 208 KB Output is correct
21 Correct 0 ms 208 KB Output is correct
22 Correct 1 ms 208 KB Output is correct
23 Correct 0 ms 208 KB Output is correct
24 Correct 1 ms 208 KB Output is correct
25 Correct 0 ms 208 KB Output is correct
26 Correct 15 ms 300 KB Output is correct
27 Correct 0 ms 208 KB Output is correct
28 Correct 0 ms 208 KB Output is correct
29 Correct 0 ms 208 KB Output is correct
30 Correct 0 ms 208 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 12 ms 300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 0 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 0 ms 208 KB Output is correct
16 Correct 17 ms 208 KB Output is correct
17 Correct 15 ms 304 KB Output is correct
18 Correct 7 ms 208 KB Output is correct
19 Correct 14 ms 300 KB Output is correct
20 Correct 14 ms 208 KB Output is correct
21 Correct 0 ms 208 KB Output is correct
22 Correct 1 ms 208 KB Output is correct
23 Correct 0 ms 208 KB Output is correct
24 Correct 1 ms 208 KB Output is correct
25 Correct 0 ms 208 KB Output is correct
26 Correct 15 ms 300 KB Output is correct
27 Correct 0 ms 208 KB Output is correct
28 Correct 0 ms 208 KB Output is correct
29 Correct 0 ms 208 KB Output is correct
30 Correct 0 ms 208 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 12 ms 300 KB Output is correct
33 Correct 63 ms 316 KB Output is correct
34 Correct 43 ms 348 KB Output is correct
35 Correct 91 ms 348 KB Output is correct
36 Correct 85 ms 296 KB Output is correct
37 Correct 84 ms 344 KB Output is correct
38 Correct 62 ms 356 KB Output is correct
39 Correct 48 ms 344 KB Output is correct
40 Correct 91 ms 352 KB Output is correct
41 Correct 87 ms 292 KB Output is correct
42 Correct 65 ms 312 KB Output is correct
43 Correct 66 ms 308 KB Output is correct
44 Correct 58 ms 536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 95 ms 308 KB Partially correct
2 Partially correct 63 ms 300 KB Partially correct
3 Partially correct 90 ms 348 KB Partially correct
4 Partially correct 60 ms 344 KB Partially correct
5 Partially correct 66 ms 352 KB Partially correct
6 Partially correct 87 ms 296 KB Partially correct
7 Partially correct 78 ms 348 KB Partially correct
8 Partially correct 100 ms 356 KB Partially correct
9 Partially correct 90 ms 340 KB Partially correct
10 Partially correct 64 ms 344 KB Partially correct
11 Partially correct 91 ms 292 KB Partially correct
12 Partially correct 87 ms 308 KB Partially correct
13 Partially correct 71 ms 336 KB Partially correct
14 Partially correct 91 ms 348 KB Partially correct
15 Partially correct 89 ms 316 KB Partially correct
16 Partially correct 95 ms 344 KB Partially correct
17 Partially correct 94 ms 328 KB Partially correct
18 Partially correct 101 ms 344 KB Partially correct