Submission #771201

# Submission time Handle Problem Language Result Execution time Memory
771201 2023-07-02T15:19:20 Z SamAnd Monster Game (JOI21_monster) C++17
0 / 100
73 ms 348 KB
#include "monster.h"
#include <algorithm>
#include <vector>
using namespace std;
#define sz(x) ((int)(x).size())

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;
                reverse(v.begin() + i, v.begin() + j + 1);
                i = j;
            }
            else
            {
                int j = i + 2;
                while (j + 1 < n && !Query(v[i], v[j + 1]))
                    ++j;
                ++j;
                if (Query(v[j], v[i + 1]))
                {
                    swap(v[i], v[i + 1]);
                    reverse(v.begin() + i + 2, v.begin() + j + 1);
                }
                else
                {
                    reverse(v.begin() + i + 1, 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 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 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 0 ms 208 KB Output is correct
8 Incorrect 0 ms 208 KB Wrong Answer [3]
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 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 0 ms 208 KB Output is correct
8 Incorrect 0 ms 208 KB Wrong Answer [3]
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 73 ms 348 KB Wrong Answer [3]
2 Halted 0 ms 0 KB -