Submission #662509

# Submission time Handle Problem Language Result Execution time Memory
662509 2022-11-26T10:27:30 Z LittleCube Monster Game (JOI21_monster) C++17
100 / 100
100 ms 320 KB
#include "monster.h"
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define piii tuple<int, int, int>
using namespace std;

vector<int> merge(vector<int> v)
{
    int n = v.size();
    if (n == 1)
        return v;

    vector<int> l, r;
    for (int i = 0; i < n; i++)
        if (i < n / 2)
            l.push_back(v[i]);
        else
            r.push_back(v[i]);

    v.clear();
    l = merge(l);
    r = merge(r);
    int ldx = 0, rdx = 0;
    while (ldx < l.size() || rdx < r.size())
    {
        if (ldx >= l.size())
            v.push_back(r[rdx++]);
        else if (rdx >= r.size())
            v.push_back(l[ldx++]);
        else if (Query(l[ldx], r[rdx]))
            v.push_back(r[rdx++]);
        else
            v.push_back(l[ldx++]);
    }
    return v;
}

vector<int> Solve(int N)
{
    vector<int> v;
    for (int i = 0; i < N; i++)
        v.push_back(i);
    v = merge(v);
    // for (int i = 0; i < N; i++)
    //     cerr << v[i] << " \n"[i == N - 1];
    int start = 0;
    if (Query(v[0], v[1]))
        start = 1;
    else if (Query(v[2], v[0]))
    {
        if (Query(v[3], v[1]))
            start = 2;
        else
            start = 1;
    }
    else if (Query(v[3], v[1]))
        for (int j = 3; j < N; j++)
        {
            if (Query(v[2], v[j]))
            {
                start = 2;
                break;
            }
            else if (Query(v[0], v[j]))
            {
                start = 3;
                break;
            }
            else if (Query(v[1], v[j]))
            {
                start = 1;
                break;
            }
        }
    else
    {
        for (int i = 2; i < N - 2; i++)
            if (Query(v[i + 2], v[i]))
            {
                start = i + 2;
                break;
            }
    }
    // cerr << start << '\n';
    reverse(v.begin(), v.begin() + start);
    for (int i = start; i < N;)
    {
        int j = i;
        while (Query(v[j], v[i - 1]))
            j++;
        j++;
        reverse(v.begin() + i, v.begin() + j);
        i = j;
    }
    // for (int i = 0; i < N; i++)
    //     cerr << v[i] << " \n"[i == N - 1];
    vector<int> T(N);
    for (int i = 0; i < N; i++)
        T[v[i]] = i;
    return T;
}

Compilation message

monster.cpp: In function 'std::vector<int> merge(std::vector<int>)':
monster.cpp:27:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     while (ldx < l.size() || rdx < r.size())
      |            ~~~~^~~~~~~~~~
monster.cpp:27:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     while (ldx < l.size() || rdx < r.size())
      |                              ~~~~^~~~~~~~~~
monster.cpp:29:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |         if (ldx >= l.size())
      |             ~~~~^~~~~~~~~~~
monster.cpp:31:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |         else if (rdx >= r.size())
      |                  ~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 248 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 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 1 ms 208 KB Output is correct
16 Correct 9 ms 208 KB Output is correct
17 Correct 14 ms 208 KB Output is correct
18 Correct 14 ms 280 KB Output is correct
19 Correct 14 ms 208 KB Output is correct
20 Correct 13 ms 208 KB Output is correct
21 Correct 1 ms 208 KB Output is correct
22 Correct 1 ms 208 KB Output is correct
23 Correct 1 ms 208 KB Output is correct
24 Correct 1 ms 208 KB Output is correct
25 Correct 1 ms 208 KB Output is correct
26 Correct 10 ms 300 KB Output is correct
27 Correct 0 ms 208 KB Output is correct
28 Correct 1 ms 208 KB Output is correct
29 Correct 1 ms 208 KB Output is correct
30 Correct 1 ms 208 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 9 ms 304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 248 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 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 1 ms 208 KB Output is correct
16 Correct 9 ms 208 KB Output is correct
17 Correct 14 ms 208 KB Output is correct
18 Correct 14 ms 280 KB Output is correct
19 Correct 14 ms 208 KB Output is correct
20 Correct 13 ms 208 KB Output is correct
21 Correct 1 ms 208 KB Output is correct
22 Correct 1 ms 208 KB Output is correct
23 Correct 1 ms 208 KB Output is correct
24 Correct 1 ms 208 KB Output is correct
25 Correct 1 ms 208 KB Output is correct
26 Correct 10 ms 300 KB Output is correct
27 Correct 0 ms 208 KB Output is correct
28 Correct 1 ms 208 KB Output is correct
29 Correct 1 ms 208 KB Output is correct
30 Correct 1 ms 208 KB Output is correct
31 Correct 1 ms 208 KB Output is correct
32 Correct 9 ms 304 KB Output is correct
33 Correct 73 ms 312 KB Output is correct
34 Correct 56 ms 208 KB Output is correct
35 Correct 94 ms 296 KB Output is correct
36 Correct 45 ms 320 KB Output is correct
37 Correct 81 ms 208 KB Output is correct
38 Correct 84 ms 208 KB Output is correct
39 Correct 78 ms 208 KB Output is correct
40 Correct 88 ms 208 KB Output is correct
41 Correct 68 ms 208 KB Output is correct
42 Correct 74 ms 208 KB Output is correct
43 Correct 43 ms 208 KB Output is correct
44 Correct 42 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 208 KB Output is correct
2 Correct 55 ms 208 KB Output is correct
3 Correct 64 ms 208 KB Output is correct
4 Correct 73 ms 208 KB Output is correct
5 Correct 92 ms 208 KB Output is correct
6 Correct 69 ms 208 KB Output is correct
7 Correct 64 ms 208 KB Output is correct
8 Correct 91 ms 208 KB Output is correct
9 Correct 100 ms 308 KB Output is correct
10 Correct 59 ms 208 KB Output is correct
11 Correct 80 ms 208 KB Output is correct
12 Correct 81 ms 208 KB Output is correct
13 Correct 57 ms 208 KB Output is correct
14 Correct 68 ms 208 KB Output is correct
15 Correct 49 ms 256 KB Output is correct
16 Correct 35 ms 208 KB Output is correct
17 Correct 79 ms 208 KB Output is correct
18 Correct 43 ms 208 KB Output is correct