Submission #545737

# Submission time Handle Problem Language Result Execution time Memory
545737 2022-04-05T10:14:43 Z alextodoran Monster Game (JOI21_monster) C++17
98 / 100
106 ms 4252 KB
#include <bits/stdc++.h>

using namespace std;

bool Query (int a, int b);

vector <vector <int>> cmp;
bool ask (int a, int b) {
    if (a > b) {
        swap(a, b);
        if (cmp[a][b] == -1) {
            cmp[a][b] = Query(a, b);
        }
        return !cmp[a][b];
    } else {
        if (cmp[a][b] == -1) {
            cmp[a][b] = Query(a, b);
        }
        return cmp[a][b];
    }
}

vector <int> Solve (int N) {
    cmp = vector <vector <int>> (N, vector <int> (N, -1));
    vector <int> order (N);
    iota(order.begin(), order.end(), 0);
    stable_sort(order.begin(), order.end(), [&] (const int &i, const int &j) {
        return ask(j, i);
    });
    int K = min(N, 10);
    vector <int> cnt (K, 0);
    for (int i = 0; i < K; i++) {
        for (int j = 0; j < K; j++) {
            if (i != j) {
                cnt[i] += ask(order[i], order[j]);
            }
        }
    }
    vector <int> aux (K);
    iota(aux.begin(), aux.end(), 0);
    sort(aux.begin(), aux.end(), [&] (const int &i, const int &j) {
        return cnt[i] < cnt[j];
    });
    int currMin = (ask(order[aux[0]], order[aux[1]]) == true ? aux[0] : aux[1]);
    reverse(order.begin(), order.begin() + currMin + 1);
    while (currMin + 1 < N) {
        int nextMin = currMin + 1;
        while (ask(order[currMin], order[nextMin]) == false) {
            nextMin++;
        }
        reverse(order.begin() + currMin + 1, order.begin() + nextMin + 1);
        currMin = nextMin;
    }
    vector <int> ret (N);
    for (int i = 0; i < N; i++) {
        ret[order[i]] = i;
    }
    return ret;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 0 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 0 ms 208 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 2 ms 208 KB Output is correct
16 Correct 15 ms 336 KB Output is correct
17 Correct 12 ms 336 KB Output is correct
18 Correct 13 ms 336 KB Output is correct
19 Correct 12 ms 336 KB Output is correct
20 Correct 10 ms 336 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 8 ms 336 KB Output is correct
27 Correct 1 ms 208 KB Output is correct
28 Correct 0 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 8 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 0 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 0 ms 208 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 2 ms 208 KB Output is correct
16 Correct 15 ms 336 KB Output is correct
17 Correct 12 ms 336 KB Output is correct
18 Correct 13 ms 336 KB Output is correct
19 Correct 12 ms 336 KB Output is correct
20 Correct 10 ms 336 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 8 ms 336 KB Output is correct
27 Correct 1 ms 208 KB Output is correct
28 Correct 0 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 8 ms 336 KB Output is correct
33 Correct 78 ms 4204 KB Output is correct
34 Correct 93 ms 4200 KB Output is correct
35 Correct 83 ms 4208 KB Output is correct
36 Correct 77 ms 4212 KB Output is correct
37 Correct 78 ms 4232 KB Output is correct
38 Correct 88 ms 4244 KB Output is correct
39 Correct 59 ms 4240 KB Output is correct
40 Correct 106 ms 4240 KB Output is correct
41 Correct 83 ms 4252 KB Output is correct
42 Correct 81 ms 4176 KB Output is correct
43 Correct 51 ms 4236 KB Output is correct
44 Correct 62 ms 4176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 85 ms 4224 KB Partially correct
2 Partially correct 83 ms 4176 KB Partially correct
3 Partially correct 40 ms 4176 KB Partially correct
4 Partially correct 81 ms 4240 KB Partially correct
5 Partially correct 78 ms 4236 KB Partially correct
6 Correct 53 ms 4176 KB Output is correct
7 Correct 63 ms 4176 KB Output is correct
8 Partially correct 83 ms 4216 KB Partially correct
9 Partially correct 86 ms 4232 KB Partially correct
10 Partially correct 86 ms 4240 KB Partially correct
11 Partially correct 86 ms 4244 KB Partially correct
12 Partially correct 84 ms 4240 KB Partially correct
13 Correct 85 ms 4236 KB Output is correct
14 Correct 39 ms 4240 KB Output is correct
15 Correct 46 ms 4240 KB Output is correct
16 Correct 46 ms 4176 KB Output is correct
17 Correct 92 ms 4240 KB Output is correct
18 Correct 62 ms 4240 KB Output is correct