답안 #891320

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
891320 2023-12-22T18:35:40 Z coldEr66 Monster Game (JOI21_monster) C++17
100 / 100
53 ms 848 KB
#include "monster.h"
#include <iostream>

using namespace std;

#define ALL(a) begin(a), end(a)
#define eb emplace_back

namespace {

bool example_variable;

}  // namespace

const int maxn = 1e3;

vector<int> id;

void mrg(int l, int r) {
    if (l == r-1) return;
    int mid = l + r >> 1;
    mrg(l, mid), mrg(mid, r);
    
    vector<int> tmp;
    for (int i = l, j = mid; i - l + j - mid < r - l;) {
        if (i < mid && (j == r || Query(id[j], id[i]))) {
            tmp.eb(id[i]);
            ++i;
        }
        else {
            tmp.eb(id[j]);
            ++j;
        }
    }
    for (int i = l; i < r; ++i) id[i] = tmp[i-l];
}

std::vector<int> Solve(int N) {
    id.resize(N);
    for (int i = 0; i < N; ++i) id[i] = i;
    mrg(0, N);

    int tr = min(15, N);

    vector<int> cnt(N);

    for (int i = 0; i < tr; ++i) {
        for (int j = i + 1; j < tr; ++j) {
            if (Query(id[i], id[j])) ++cnt[i];
            else ++cnt[j];
        }
    }
    
    int zero = -1;
    for (int i = 0; i < tr; ++i) {
        if (cnt[i] != 1) continue;
        if (zero == -1) zero = i;
        else if (!Query(id[zero], id[i])) zero = i;
    }

    std::vector<int> T(N);
    int st = 0, idx = 0;
    while (st < N) {
        int nxt = zero;
        for (int i = nxt; i >= st; --i) T[id[i]] = idx++;

        if (nxt + 1 < N) {
            ++nxt;
            while (Query(id[nxt], id[st])) ++nxt;
        }

        st = zero + 1;
        zero = nxt;
    }

    return T;
}

Compilation message

monster.cpp: In function 'void mrg(int, int)':
monster.cpp:21:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   21 |     int mid = l + r >> 1;
      |               ~~^~~
monster.cpp: At global scope:
monster.cpp:11:6: warning: '{anonymous}::example_variable' defined but not used [-Wunused-variable]
   11 | bool example_variable;
      |      ^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 360 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 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 0 ms 344 KB Output is correct
16 Correct 6 ms 600 KB Output is correct
17 Correct 5 ms 600 KB Output is correct
18 Correct 6 ms 436 KB Output is correct
19 Correct 6 ms 440 KB Output is correct
20 Correct 5 ms 600 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 0 ms 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 5 ms 600 KB Output is correct
27 Correct 1 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 0 ms 344 KB Output is correct
32 Correct 5 ms 600 KB Output is correct
# 결과 실행 시간 메모리 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 360 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 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 0 ms 344 KB Output is correct
16 Correct 6 ms 600 KB Output is correct
17 Correct 5 ms 600 KB Output is correct
18 Correct 6 ms 436 KB Output is correct
19 Correct 6 ms 440 KB Output is correct
20 Correct 5 ms 600 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 0 ms 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 5 ms 600 KB Output is correct
27 Correct 1 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 0 ms 344 KB Output is correct
32 Correct 5 ms 600 KB Output is correct
33 Correct 40 ms 668 KB Output is correct
34 Correct 43 ms 600 KB Output is correct
35 Correct 43 ms 672 KB Output is correct
36 Correct 39 ms 668 KB Output is correct
37 Correct 39 ms 600 KB Output is correct
38 Correct 38 ms 596 KB Output is correct
39 Correct 39 ms 848 KB Output is correct
40 Correct 37 ms 684 KB Output is correct
41 Correct 46 ms 596 KB Output is correct
42 Correct 38 ms 436 KB Output is correct
43 Correct 25 ms 600 KB Output is correct
44 Correct 23 ms 672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 420 KB Output is correct
2 Correct 40 ms 600 KB Output is correct
3 Correct 37 ms 672 KB Output is correct
4 Correct 44 ms 672 KB Output is correct
5 Correct 45 ms 600 KB Output is correct
6 Correct 32 ms 600 KB Output is correct
7 Correct 33 ms 600 KB Output is correct
8 Correct 53 ms 848 KB Output is correct
9 Correct 34 ms 668 KB Output is correct
10 Correct 40 ms 600 KB Output is correct
11 Correct 53 ms 424 KB Output is correct
12 Correct 37 ms 600 KB Output is correct
13 Correct 31 ms 672 KB Output is correct
14 Correct 35 ms 440 KB Output is correct
15 Correct 25 ms 600 KB Output is correct
16 Correct 22 ms 416 KB Output is correct
17 Correct 40 ms 440 KB Output is correct
18 Correct 30 ms 600 KB Output is correct