Submission #895290

# Submission time Handle Problem Language Result Execution time Memory
895290 2023-12-29T17:49:30 Z GrandTiger1729 Monster Game (JOI21_monster) C++17
75 / 100
51 ms 688 KB
#include "monster.h"
#include <bits/stdc++.h>
using namespace std;

vector<int> Solve(int n)
{
    vector<int> ord(n);
    iota(ord.begin(), ord.end(), 0);
    function<void(int, int)> solve = [&](int l, int r)
    {
        if (l == r - 1)
        {
            return;
        }
        int mid = (l + r) / 2;
        solve(l, mid);
        solve(mid, r);
        int i = l, j = mid;
        vector<int> res;
        while (i < mid && j < r)
        {
            if (!Query(ord[i], ord[j]))
            {
                res.push_back(ord[i]);
                i++;
            }
            else
            {
                res.push_back(ord[j]);
                j++;
            }
        }
        while (i < mid)
        {
            res.push_back(ord[i]);
            i++;
        }
        while (j < r)
        {
            res.push_back(ord[j]);
            j++;
        }
        for (int k = l; k < r; k++)
        {
            ord[k] = res[k - l];
        }
    };
    solve(0, n);
    auto solve4 = [&]()
    {
        if (Query(ord[0], ord[3]))
        {
            swap(ord[0], ord[2]);
        }
        else if (Query(ord[1], ord[3]))
        {
            swap(ord[1], ord[2]);
        }
        else
        {
            swap(ord[0], ord[1]);
        }
    };
    auto solve6 = [&]()
    {
        for (int i = 0; i < 3; i++)
        {
            for (int j = 3; j < 6; j++)
            {
                if (Query(ord[i], ord[j]))
                {
                    swap(ord[2], ord[i]);
                    swap(ord[3], ord[j]);
                    goto found;
                }
            }
        }
        found:
        if (Query(ord[0], ord[2]))
        {
            swap(ord[0], ord[1]);
        }
        if (Query(ord[3], ord[5]))
        {
            swap(ord[4], ord[5]);
        }
    };
    auto get = [&]() -> int
    {
        if (!Query(ord[0], ord[2]))
        {
            int j = 3;
            while (j < n && !Query(ord[0], ord[j]))
            {
                j++;
            }
            if (Query(ord[1], ord[j]))
            {
                reverse(ord.begin() + 1, ord.begin() + j + 1);
            }
            else
            {
                swap(ord[0], ord[1]);
                reverse(ord.begin() + 2, ord.begin() + j + 1);
            }
            return j + 1;
        }
        if (Query(ord[0], ord[3]))
        {
            if (Query(ord[1], ord[3]))
            {
                int j = 4;
                while (j < n && Query(ord[1], ord[j]))
                {
                    j++;
                }
                reverse(ord.begin(), ord.begin() + j);
                return j;
            }
        }
        if (n == 4)
        {
            solve4();
            return 4;
        }
        if (n == 5)
        {
            swap(ord[3], ord[4]);
            solve4();
            return 5;
        }
        if (n == 6)
        {
            solve6();
            return 6;
        }
        if (!Query(ord[3], ord[5]))
        {
            int j = 6;
            while (j < n && !Query(ord[3], ord[j]))
            {
                j++;
            }
            if (Query(ord[4], ord[j]))
            {
                reverse(ord.begin() + 4, ord.begin() + j + 1);
            }
            else
            {
                swap(ord[3], ord[4]);
                reverse(ord.begin() + 5, ord.begin() + j + 1);
            }
            if (Query(ord[0], ord[3]))
            {
                swap(ord[0], ord[2]);
            }
            else
            {
                swap(ord[1], ord[2]);
            }
            return j + 1;
        }
        if (Query(ord[3], ord[6]))
        {
            if (Query(ord[4], ord[6]))
            {
                int j = 7;
                while (j < n && Query(ord[4], ord[j]))
                {
                    j++;
                }
                reverse(ord.begin() + 3, ord.begin() + j);
                if (Query(ord[0], ord[3]))
                {
                    swap(ord[0], ord[2]);
                }
                else
                {
                    swap(ord[1], ord[2]);
                }
                return j;
            }
        }
        solve6();
        return 6;
    };
    int i = get();
    while (i < n)
    {
        int j = i;
        while (j < n && !Query(ord[i - 1], ord[j]))
        {
            j++;
        }
        reverse(ord.begin() + i, ord.begin() + j + 1);
        i = j + 1;
    }
    vector<int> ans(n);
    for (int i = 0; i < n; i++)
    {
        ans[ord[i]] = i;
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 596 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Incorrect 0 ms 344 KB Wrong Answer [3]
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 596 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Incorrect 0 ms 344 KB Wrong Answer [3]
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 41 ms 600 KB Output is correct
2 Correct 45 ms 440 KB Output is correct
3 Correct 51 ms 600 KB Output is correct
4 Correct 46 ms 592 KB Output is correct
5 Correct 49 ms 600 KB Output is correct
6 Correct 34 ms 600 KB Output is correct
7 Correct 39 ms 424 KB Output is correct
8 Correct 34 ms 424 KB Output is correct
9 Correct 45 ms 440 KB Output is correct
10 Correct 44 ms 600 KB Output is correct
11 Correct 47 ms 600 KB Output is correct
12 Correct 42 ms 672 KB Output is correct
13 Correct 36 ms 600 KB Output is correct
14 Correct 35 ms 688 KB Output is correct
15 Correct 22 ms 600 KB Output is correct
16 Correct 22 ms 600 KB Output is correct
17 Correct 36 ms 600 KB Output is correct
18 Correct 24 ms 436 KB Output is correct