답안 #545735

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
545735 2022-04-05T10:13:28 Z alextodoran Monster Game (JOI21_monster) C++17
100 / 100
84 ms 4260 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];
    }
}

void mergeSort (vector <int> :: iterator l, vector <int> :: iterator r) {
    int len = r - l;
    if (len != 1) {
        int mid = len / 2;
        mergeSort(l, l + mid);
        mergeSort(l + mid, r);
        vector <int> aux (len);
        merge(l, l + mid, l + mid, r, aux.begin(), [&] (const int &i, const int &j) {
            return ask(j, i);
        });
        copy(aux.begin(), aux.end(), l);
    }
}

vector <int> Solve (int N) {
    cmp = vector <vector <int>> (N, vector <int> (N, -1));
    vector <int> order (N);
    iota(order.begin(), order.end(), 0);
    mergeSort(order.begin(), order.end());
    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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 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 208 KB Output is correct
10 Correct 0 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 16 ms 336 KB Output is correct
17 Correct 12 ms 336 KB Output is correct
18 Correct 16 ms 464 KB Output is correct
19 Correct 12 ms 464 KB Output is correct
20 Correct 11 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 6 ms 468 KB Output is correct
27 Correct 1 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 11 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 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 208 KB Output is correct
10 Correct 0 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 16 ms 336 KB Output is correct
17 Correct 12 ms 336 KB Output is correct
18 Correct 16 ms 464 KB Output is correct
19 Correct 12 ms 464 KB Output is correct
20 Correct 11 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 6 ms 468 KB Output is correct
27 Correct 1 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 11 ms 460 KB Output is correct
33 Correct 36 ms 4176 KB Output is correct
34 Correct 70 ms 4212 KB Output is correct
35 Correct 84 ms 4220 KB Output is correct
36 Correct 65 ms 4216 KB Output is correct
37 Correct 64 ms 4248 KB Output is correct
38 Correct 54 ms 4260 KB Output is correct
39 Correct 78 ms 4128 KB Output is correct
40 Correct 70 ms 4244 KB Output is correct
41 Correct 71 ms 4240 KB Output is correct
42 Correct 75 ms 4256 KB Output is correct
43 Correct 40 ms 4248 KB Output is correct
44 Correct 44 ms 4176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 4216 KB Output is correct
2 Correct 65 ms 4232 KB Output is correct
3 Correct 54 ms 4256 KB Output is correct
4 Correct 77 ms 4240 KB Output is correct
5 Correct 67 ms 4176 KB Output is correct
6 Correct 56 ms 4244 KB Output is correct
7 Correct 41 ms 4256 KB Output is correct
8 Correct 62 ms 4216 KB Output is correct
9 Correct 76 ms 4232 KB Output is correct
10 Correct 79 ms 4240 KB Output is correct
11 Correct 78 ms 4256 KB Output is correct
12 Correct 66 ms 4232 KB Output is correct
13 Correct 65 ms 4256 KB Output is correct
14 Correct 52 ms 4132 KB Output is correct
15 Correct 52 ms 4252 KB Output is correct
16 Correct 48 ms 4252 KB Output is correct
17 Correct 81 ms 4244 KB Output is correct
18 Correct 46 ms 4252 KB Output is correct