Submission #530946

# Submission time Handle Problem Language Result Execution time Memory
530946 2022-02-27T07:46:15 Z c28dnv9q3 Monster Game (JOI21_monster) C++17
100 / 100
138 ms 4236 KB
#include "monster.h"
#include <iostream>
#include <bits/stdc++.h>

using namespace std;

const int len = 12;

void print(string pre, vector<int> a) {
    return;
    cout << pre << " ";
    for (int i = 0; i < a.size(); ++i) {
        cout << a[i] << " ";
    }
    cout << "\n";
}

int higher[1 << len];
map<pair<int, int>, int> quer;

bool cmp(int a, int b, int N) {
    if (a >= N) return true;
    if (b >= N) return false;
    //cout << a << " " << b << "\n";
    bool q = Query(a, b);
    if (q) higher[a]++; else higher[b]++;
    return q;
}

bool compare(int a, int b, int N) {
    if (quer[{a, b}] != 0) return quer[{a, b}] == 2;
    bool q = cmp(a, b, N);
    quer[{a, b}] = q ? 2 : 1;
    quer[{b, a}] = q ? 1 : 2;
    return q;
}

vector<int> sort(int l, int o, int N) {
    if (l == 0) return std::vector<int>{o};
    vector<int> a = sort(l - 1, o, N);
    vector<int> b = sort(l - 1, o + (1 << (l - 1)), N);
    vector<int> c(a.size() + b.size());
    int iA = 0;
    int iB = 0;
    for (int i = 0; i < c.size(); ++i) {
        if (iA < a.size() && iB < b.size()) {
            if (compare(a[iA], b[iB], N)) {
                c[i] = b[iB++];
            } else {
                c[i] = a[iA++];
            }
        } else {
            if (iA == a.size()) {
                c[i] = b[iB++];
            } else {
                c[i] = a[iA++];
            }
        }
    }
    return c;
}

void rev(vector<int> &T, int a, int b) {
    for (int i = 0; i < (1 + b - a) / 2; ++i) {
        swap(T[a + i], T[b - i]);
    }
}

int findMin(int N) {
    vector<int> low;

    for (int i = 0; i < N; ++i) {
        if (higher[i] <= 3) low.push_back(i);
    }

    print("possible: ", low);

    for (int i = 0; i < low.size(); ++i) {
        for (int j = 0; j < low.size(); ++j) {
            if (i == j) continue;
            if (higher[low[i]] > 3 || higher[low[j]] > 3) continue;
            compare(low[i], low[j], N);
        }
    }

    print("possible: ", low);

    vector<int> min;
    for (int i = 0; i < low.size(); ++i) {
        if (higher[low[i]] == 1) min.push_back(low[i]);
    }

    print("last: ", min);

    //for (int i = 0; i < N; ++i) cout << higher[i]; cout << "\n";

    return compare(min[0], min[1], N) ? min[0] : min[1];
}

std::vector<int> Solve(int N) {
    vector<int> T = sort(len, 0, N);

    int ind = -1;
    int x = findMin(N);
    for (int i = 0; i < N; ++i) {
        if (T[i] == x) ind = i;
    }
    if (ind == -1) return {};
    rev(T, 0, ind);

    for (int s = ind; s < N - 1;) {
        for (int i = s + 1; i < N; ++i) {
            if (compare(T[s], T[i], N)) {
                rev(T, s + 1, i);
                s = i;
                break;
            }
            if (i == N - 1) return {};
        }
    }

    vector<int> erg = vector<int>(N, 0);
    for (int i = 0; i < N; ++i) {
        erg[T[i]] = i;
    }

    return erg;
}

Compilation message

monster.cpp: In function 'void print(std::string, std::vector<int>)':
monster.cpp:12:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for (int i = 0; i < a.size(); ++i) {
      |                     ~~^~~~~~~~~~
monster.cpp: In function 'std::vector<int> sort(int, int, int)':
monster.cpp:45:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for (int i = 0; i < c.size(); ++i) {
      |                     ~~^~~~~~~~~~
monster.cpp:46:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         if (iA < a.size() && iB < b.size()) {
      |             ~~~^~~~~~~~~~
monster.cpp:46:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         if (iA < a.size() && iB < b.size()) {
      |                              ~~~^~~~~~~~~~
monster.cpp:53:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |             if (iA == a.size()) {
      |                 ~~~^~~~~~~~~~~
monster.cpp: In function 'int findMin(int)':
monster.cpp:78:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |     for (int i = 0; i < low.size(); ++i) {
      |                     ~~^~~~~~~~~~~~
monster.cpp:79:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |         for (int j = 0; j < low.size(); ++j) {
      |                         ~~^~~~~~~~~~~~
monster.cpp:89:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |     for (int i = 0; i < low.size(); ++i) {
      |                     ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 11 ms 3400 KB Output is correct
2 Correct 13 ms 3400 KB Output is correct
3 Correct 11 ms 3400 KB Output is correct
4 Correct 12 ms 3372 KB Output is correct
5 Correct 11 ms 3392 KB Output is correct
6 Correct 12 ms 3292 KB Output is correct
7 Correct 11 ms 3344 KB Output is correct
8 Correct 13 ms 3288 KB Output is correct
9 Correct 13 ms 3400 KB Output is correct
10 Correct 11 ms 3400 KB Output is correct
11 Correct 15 ms 3384 KB Output is correct
12 Correct 10 ms 3400 KB Output is correct
13 Correct 11 ms 3404 KB Output is correct
14 Correct 10 ms 3400 KB Output is correct
15 Correct 11 ms 3400 KB Output is correct
16 Correct 26 ms 3440 KB Output is correct
17 Correct 37 ms 3536 KB Output is correct
18 Correct 27 ms 3524 KB Output is correct
19 Correct 31 ms 3556 KB Output is correct
20 Correct 24 ms 3540 KB Output is correct
21 Correct 11 ms 3364 KB Output is correct
22 Correct 12 ms 3400 KB Output is correct
23 Correct 10 ms 3400 KB Output is correct
24 Correct 11 ms 3296 KB Output is correct
25 Correct 11 ms 3400 KB Output is correct
26 Correct 27 ms 3524 KB Output is correct
27 Correct 11 ms 3400 KB Output is correct
28 Correct 14 ms 3420 KB Output is correct
29 Correct 17 ms 3400 KB Output is correct
30 Correct 11 ms 3368 KB Output is correct
31 Correct 15 ms 3328 KB Output is correct
32 Correct 21 ms 3444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 3400 KB Output is correct
2 Correct 13 ms 3400 KB Output is correct
3 Correct 11 ms 3400 KB Output is correct
4 Correct 12 ms 3372 KB Output is correct
5 Correct 11 ms 3392 KB Output is correct
6 Correct 12 ms 3292 KB Output is correct
7 Correct 11 ms 3344 KB Output is correct
8 Correct 13 ms 3288 KB Output is correct
9 Correct 13 ms 3400 KB Output is correct
10 Correct 11 ms 3400 KB Output is correct
11 Correct 15 ms 3384 KB Output is correct
12 Correct 10 ms 3400 KB Output is correct
13 Correct 11 ms 3404 KB Output is correct
14 Correct 10 ms 3400 KB Output is correct
15 Correct 11 ms 3400 KB Output is correct
16 Correct 26 ms 3440 KB Output is correct
17 Correct 37 ms 3536 KB Output is correct
18 Correct 27 ms 3524 KB Output is correct
19 Correct 31 ms 3556 KB Output is correct
20 Correct 24 ms 3540 KB Output is correct
21 Correct 11 ms 3364 KB Output is correct
22 Correct 12 ms 3400 KB Output is correct
23 Correct 10 ms 3400 KB Output is correct
24 Correct 11 ms 3296 KB Output is correct
25 Correct 11 ms 3400 KB Output is correct
26 Correct 27 ms 3524 KB Output is correct
27 Correct 11 ms 3400 KB Output is correct
28 Correct 14 ms 3420 KB Output is correct
29 Correct 17 ms 3400 KB Output is correct
30 Correct 11 ms 3368 KB Output is correct
31 Correct 15 ms 3328 KB Output is correct
32 Correct 21 ms 3444 KB Output is correct
33 Correct 97 ms 4056 KB Output is correct
34 Correct 108 ms 4072 KB Output is correct
35 Correct 105 ms 4096 KB Output is correct
36 Correct 100 ms 4140 KB Output is correct
37 Correct 88 ms 4188 KB Output is correct
38 Correct 56 ms 4068 KB Output is correct
39 Correct 130 ms 4152 KB Output is correct
40 Correct 137 ms 4104 KB Output is correct
41 Correct 91 ms 4236 KB Output is correct
42 Correct 132 ms 4152 KB Output is correct
43 Correct 99 ms 3904 KB Output is correct
44 Correct 85 ms 3992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 102 ms 4108 KB Output is correct
2 Correct 112 ms 4172 KB Output is correct
3 Correct 113 ms 4072 KB Output is correct
4 Correct 86 ms 4084 KB Output is correct
5 Correct 100 ms 4112 KB Output is correct
6 Correct 100 ms 4152 KB Output is correct
7 Correct 84 ms 4156 KB Output is correct
8 Correct 127 ms 4136 KB Output is correct
9 Correct 107 ms 4096 KB Output is correct
10 Correct 138 ms 4052 KB Output is correct
11 Correct 84 ms 4096 KB Output is correct
12 Correct 90 ms 4056 KB Output is correct
13 Correct 105 ms 4160 KB Output is correct
14 Correct 129 ms 4140 KB Output is correct
15 Correct 100 ms 3892 KB Output is correct
16 Correct 78 ms 3912 KB Output is correct
17 Correct 118 ms 4236 KB Output is correct
18 Correct 103 ms 3912 KB Output is correct