답안 #699037

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
699037 2023-02-15T12:09:44 Z KoD 게임 (APIO22_game) C++17
100 / 100
1617 ms 68076 KB
#include "game.h"
#include <algorithm>
#include <utility>
#include <vector>

namespace kod {

using namespace std;

int n, k;
vector<int> l, r;
vector<vector<int>> in, out;

int get_level(const int u) { return l[u] >= r[u] ? 0 : 32 - __builtin_clz(l[u] ^ r[u]); }

bool check_vertex(const int u);
bool check_edge(const int u, const int v);

bool check_vertex(const int x) {
    for (const int y : out[x]) {
        if (check_edge(x, y)) {
            return true;
        }
    }
    for (const int y : in[x]) {
        if (check_edge(y, x)) {
            return true;
        }
    }
    return false;
}

bool check_edge(const int u, const int v) {
    const int u0 = get_level(u);
    const int v0 = get_level(v);
    r[u] = min(r[u], v <= k ? v : r[v]);
    l[v] = max(l[v], u <= k ? u : l[u]);
    const int u1 = get_level(u);
    const int v1 = get_level(v);
    if (u1 == 0 or v1 == 0) {
        return true;
    }
    if (u1 < u0 and check_vertex(u)) {
        return true;
    }
    if (v1 < v0 and check_vertex(v)) {
        return true;
    }
    return false;
}

int add_edge(const int u, const int v) {
    in[v].push_back(u);
    out[u].push_back(v);
    return check_edge(u, v);
}

void init(const int n_, const int k_) {
    n = n_;
    k = k_;
    l.resize(n + 1, 0);
    r.resize(n + 1, n + 1);
    in.resize(n + 1);
    out.resize(n + 1);
    for (int i = 1; i <= k - 1; ++i) {
        add_edge(i, i + 1);
    }
}

}  // namespace kod

void init(int n, int k) { kod::init(n, k); }

int add_teleporter(int u, int v) { return kod::add_edge(u + 1, v + 1); }
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 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 0 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 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 0 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 0 ms 208 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 0 ms 208 KB Output is correct
14 Correct 0 ms 208 KB Output is correct
15 Correct 0 ms 280 KB Output is correct
16 Correct 0 ms 208 KB Output is correct
17 Correct 0 ms 208 KB Output is correct
18 Correct 0 ms 208 KB Output is correct
19 Correct 0 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 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 0 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 0 ms 208 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 0 ms 208 KB Output is correct
14 Correct 0 ms 208 KB Output is correct
15 Correct 0 ms 280 KB Output is correct
16 Correct 0 ms 208 KB Output is correct
17 Correct 0 ms 208 KB Output is correct
18 Correct 0 ms 208 KB Output is correct
19 Correct 0 ms 208 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 0 ms 336 KB Output is correct
22 Correct 2 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 464 KB Output is correct
25 Correct 3 ms 464 KB Output is correct
26 Correct 3 ms 336 KB Output is correct
27 Correct 2 ms 404 KB Output is correct
28 Correct 2 ms 336 KB Output is correct
29 Correct 3 ms 408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 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 0 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 0 ms 208 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 0 ms 208 KB Output is correct
14 Correct 0 ms 208 KB Output is correct
15 Correct 0 ms 280 KB Output is correct
16 Correct 0 ms 208 KB Output is correct
17 Correct 0 ms 208 KB Output is correct
18 Correct 0 ms 208 KB Output is correct
19 Correct 0 ms 208 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 0 ms 336 KB Output is correct
22 Correct 2 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 464 KB Output is correct
25 Correct 3 ms 464 KB Output is correct
26 Correct 3 ms 336 KB Output is correct
27 Correct 2 ms 404 KB Output is correct
28 Correct 2 ms 336 KB Output is correct
29 Correct 3 ms 408 KB Output is correct
30 Correct 19 ms 3020 KB Output is correct
31 Correct 6 ms 2384 KB Output is correct
32 Correct 19 ms 5140 KB Output is correct
33 Correct 18 ms 3852 KB Output is correct
34 Correct 38 ms 7800 KB Output is correct
35 Correct 38 ms 5176 KB Output is correct
36 Correct 44 ms 3924 KB Output is correct
37 Correct 31 ms 3848 KB Output is correct
38 Correct 25 ms 3536 KB Output is correct
39 Correct 27 ms 3608 KB Output is correct
40 Correct 42 ms 7648 KB Output is correct
41 Correct 31 ms 4628 KB Output is correct
42 Correct 28 ms 4272 KB Output is correct
43 Correct 36 ms 5284 KB Output is correct
44 Correct 46 ms 6556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 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 0 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 0 ms 208 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 0 ms 208 KB Output is correct
14 Correct 0 ms 208 KB Output is correct
15 Correct 0 ms 280 KB Output is correct
16 Correct 0 ms 208 KB Output is correct
17 Correct 0 ms 208 KB Output is correct
18 Correct 0 ms 208 KB Output is correct
19 Correct 0 ms 208 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 0 ms 336 KB Output is correct
22 Correct 2 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 464 KB Output is correct
25 Correct 3 ms 464 KB Output is correct
26 Correct 3 ms 336 KB Output is correct
27 Correct 2 ms 404 KB Output is correct
28 Correct 2 ms 336 KB Output is correct
29 Correct 3 ms 408 KB Output is correct
30 Correct 19 ms 3020 KB Output is correct
31 Correct 6 ms 2384 KB Output is correct
32 Correct 19 ms 5140 KB Output is correct
33 Correct 18 ms 3852 KB Output is correct
34 Correct 38 ms 7800 KB Output is correct
35 Correct 38 ms 5176 KB Output is correct
36 Correct 44 ms 3924 KB Output is correct
37 Correct 31 ms 3848 KB Output is correct
38 Correct 25 ms 3536 KB Output is correct
39 Correct 27 ms 3608 KB Output is correct
40 Correct 42 ms 7648 KB Output is correct
41 Correct 31 ms 4628 KB Output is correct
42 Correct 28 ms 4272 KB Output is correct
43 Correct 36 ms 5284 KB Output is correct
44 Correct 46 ms 6556 KB Output is correct
45 Correct 243 ms 28096 KB Output is correct
46 Correct 13 ms 17216 KB Output is correct
47 Correct 13 ms 17152 KB Output is correct
48 Correct 325 ms 49736 KB Output is correct
49 Correct 252 ms 35536 KB Output is correct
50 Correct 768 ms 57488 KB Output is correct
51 Correct 928 ms 46716 KB Output is correct
52 Correct 565 ms 35460 KB Output is correct
53 Correct 764 ms 35848 KB Output is correct
54 Correct 764 ms 35856 KB Output is correct
55 Correct 1248 ms 35728 KB Output is correct
56 Correct 1293 ms 35944 KB Output is correct
57 Correct 505 ms 35872 KB Output is correct
58 Correct 450 ms 35908 KB Output is correct
59 Correct 486 ms 35864 KB Output is correct
60 Correct 504 ms 36020 KB Output is correct
61 Correct 564 ms 35876 KB Output is correct
62 Correct 585 ms 43208 KB Output is correct
63 Correct 555 ms 39948 KB Output is correct
64 Correct 1475 ms 68076 KB Output is correct
65 Correct 573 ms 37508 KB Output is correct
66 Correct 462 ms 33452 KB Output is correct
67 Correct 884 ms 42880 KB Output is correct
68 Correct 213 ms 29444 KB Output is correct
69 Correct 57 ms 23420 KB Output is correct
70 Correct 823 ms 45528 KB Output is correct
71 Correct 316 ms 30280 KB Output is correct
72 Correct 229 ms 26352 KB Output is correct
73 Correct 702 ms 40312 KB Output is correct
74 Correct 1400 ms 36120 KB Output is correct
75 Correct 1280 ms 50040 KB Output is correct
76 Correct 1617 ms 62296 KB Output is correct