Submission #1035258

# Submission time Handle Problem Language Result Execution time Memory
1035258 2024-07-26T08:04:03 Z CommandMaster Monster Game (JOI21_monster) C++17
98 / 100
77 ms 960 KB
#include "monster.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>

std::vector<int> Solve(int N) {
    std::vector<int> arr;
    // vector<vector<int>> triangles;
    vector<vector<int>> data(N);

    for (int i = 0; i < N; i++) {
        // for (int v : arr) cout << S[v] << ' ';
        // cout << '\n';

        // cout << "----------\n";

        // for (vector<int> v : triangles) {
        //     for (int c : v)
        //         cout << S[c] << ' ';
        //     cout << '\n';
        // }

        // cout << endl;

        int ins_ind = 0;

        // if (!arr.empty() && !Query(arr[0], i))
        ins_ind = lower_bound(arr.begin(), arr.end(), i, [&](ll a, ll b){return Query(b, a);}) - arr.begin();
        if (2 <= ins_ind && data[arr[ins_ind-1]].empty() && data[arr[ins_ind-2]].size() < 5 && !Query(i, arr[ins_ind - 2])) {
            vector<int>& v = data[arr[ins_ind-2]];
            if (v.empty()) {
                v = {i, arr[ins_ind - 1], arr[ins_ind - 2]};
            } else {
                if (Query(i, v[1])) {
                    v = {v[0], v[1], v[2], i, arr[ins_ind - 1]};
                } else {
                    v = {i, arr[ins_ind - 1], v[2], v[0], v[1]};
                }
            }
            arr.erase(arr.begin() + ins_ind - 1);
        } else if (ins_ind + 1 < arr.size() && data[arr[ins_ind]].empty() && data[arr[ins_ind+1]].size() < 5 && Query(i, arr[ins_ind + 1])) {
            vector<int>& v = data[arr[ins_ind+1]];
            if (v.empty()) {
                v = {arr[ins_ind], i, arr[ins_ind + 1]};
            } else {
                if (Query(i, v[1])) {
                    v = {v[0], v[1], v[2], arr[ins_ind], i};
                } else {
                    v = {arr[ins_ind], i, v[2], v[0], v[1]};
                }
            }
            arr.erase(arr.begin() + ins_ind);
        } else {
            arr.insert(arr.begin() + ins_ind, i);
        }
    }

    // for (int c : arr) cout << S[c] << ' ';
    // cout << "\n-------------\n";
    // for (int c : arr) {
    //     for (int v : data[c]) cout << S[v] << ' ';
    //     cout << '\n';
    // }
    // cout << "-------------\n";

    vector<vector<int>> rarr;

    for (int v : arr) {
        if (data[v].empty()) {
            if (!rarr.empty() && (rarr.back().size() == 3) && !Query(v, rarr.back()[0])) {
                if (Query(v, rarr.back()[1]))
                    rarr.back() = {rarr.back()[1], rarr.back()[2], rarr.back()[0], v};
                else
                    rarr.back() = {v, rarr.back()[2], rarr.back()[0], rarr.back()[1]};
            } else
                rarr.push_back({v});
        } else {
            if (!rarr.empty() && (rarr.back().size() == 1 || rarr.back().size() == 3) && data[v].size() == 3 && !Query(data[v][0], rarr.back()[0]) && !Query(data[v][1], rarr.back()[0])) {
                if (rarr.back().size() == 1) {
                    rarr.back() = {data[v][0], data[v][1], data[v][2], rarr.back()[0]};
                } else {
                    rarr.back() = {data[v][0], data[v][1], data[v][2], rarr.back()[2], rarr.back()[0], rarr.back()[1]};
                }
            }
            else
                rarr.push_back(data[v]);
        }
    }

    for (int i = 0; i + 1 < rarr.size(); i++) {
        if (rarr[i].size() == 1 && rarr[i+1].size() == 1) {
            rarr[i] = {rarr[i+1][0], rarr[i][0]};
            rarr[i+1].clear();
        }
    }


    // for (vector<int> d : rarr) {
    //     for (int c : d) cout << S[c] << ' ';
    //     cout << '\n';
    // }

    arr.clear();
    bool unsure = true;

    for (vector<int> d : rarr) {
        if (d.empty()) continue;
        if (d.size() != 3) {
            if (!arr.empty() && unsure) {
                assert(arr.size() == 3);
                for (int a = 0; a < 3; a++) {
                    arr = {arr[2], arr[0], arr[1]};
                    if (Query(arr[2], d[0])) {
                        arr.insert(arr.end(), d.begin(), d.end());
                        unsure = false;
                        goto OUT;
                    }
                }
            }
            arr.insert(arr.end(), d.begin(), d.end());
            unsure = false;
        } else {
            if (arr.empty()) arr = d;
            else {
                if (unsure) {
                    assert(arr.size() == 3);
                    for (int a = 0; a < 3; a++) {
                        arr = {arr[2], arr[0], arr[1]};
                        for (int b = 0; b < 3; b++) {
                            d = {d[2], d[0], d[1]};
                            if (Query(arr[2], d[0])) {
                                arr.insert(arr.end(), d.begin(), d.end());
                                unsure = false;
                                goto OUT;
                            }
                        }
                    }
                } else {
                    for (int b = 0; b < 2; b++) {
                        d = {d[2], d[0], d[1]};
                        if (Query(arr.back(), d[0])) {
                            arr.insert(arr.end(), d.begin(), d.end());
                            goto OUT;
                        }
                    }
                    d = {d[2], d[0], d[1]};
                    arr.insert(arr.end(), d.begin(), d.end());
                }
            }
        }
        OUT:;
    }

    // for (int v : arr) cout << S[v] << ' ';
    // cout << '\n';

    vector<int> T(N);

    for (int i = 0; i < N; i++) T[arr[i]] = i;


    // cout << "----------\n";

    // for (vector<int> v : triangles) {
    //     for (int c : v)
    //         cout << S[c] << ' ';
    //     cout << '\n';
    // }

    return T;
}

Compilation message

monster.cpp: In function 'std::vector<int> Solve(int)':
monster.cpp:42:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |         } else if (ins_ind + 1 < arr.size() && data[arr[ins_ind]].empty() && data[arr[ins_ind+1]].size() < 5 && Query(i, arr[ins_ind + 1])) {
      |                    ~~~~~~~~~~~~^~~~~~~~~~~~
monster.cpp:91:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |     for (int i = 0; i + 1 < rarr.size(); i++) {
      |                     ~~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 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 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 10 ms 344 KB Output is correct
17 Correct 7 ms 344 KB Output is correct
18 Correct 6 ms 344 KB Output is correct
19 Correct 5 ms 344 KB Output is correct
20 Correct 10 ms 440 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 3 ms 344 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 6 ms 440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 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 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 10 ms 344 KB Output is correct
17 Correct 7 ms 344 KB Output is correct
18 Correct 6 ms 344 KB Output is correct
19 Correct 5 ms 344 KB Output is correct
20 Correct 10 ms 440 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 3 ms 344 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 6 ms 440 KB Output is correct
33 Correct 47 ms 444 KB Output is correct
34 Correct 51 ms 456 KB Output is correct
35 Correct 77 ms 728 KB Output is correct
36 Correct 52 ms 848 KB Output is correct
37 Correct 40 ms 592 KB Output is correct
38 Correct 42 ms 460 KB Output is correct
39 Correct 40 ms 600 KB Output is correct
40 Correct 53 ms 592 KB Output is correct
41 Correct 52 ms 444 KB Output is correct
42 Correct 42 ms 600 KB Output is correct
43 Correct 29 ms 956 KB Output is correct
44 Correct 39 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 43 ms 344 KB Partially correct
2 Partially correct 43 ms 700 KB Partially correct
3 Partially correct 57 ms 708 KB Partially correct
4 Partially correct 45 ms 592 KB Partially correct
5 Partially correct 47 ms 852 KB Partially correct
6 Correct 38 ms 592 KB Output is correct
7 Correct 26 ms 600 KB Output is correct
8 Partially correct 51 ms 952 KB Partially correct
9 Partially correct 52 ms 452 KB Partially correct
10 Partially correct 47 ms 948 KB Partially correct
11 Partially correct 44 ms 960 KB Partially correct
12 Partially correct 56 ms 848 KB Partially correct
13 Correct 53 ms 848 KB Output is correct
14 Correct 40 ms 704 KB Output is correct
15 Correct 35 ms 440 KB Output is correct
16 Correct 37 ms 712 KB Output is correct
17 Correct 48 ms 456 KB Output is correct
18 Correct 33 ms 344 KB Output is correct