답안 #712995

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
712995 2023-03-20T18:32:00 Z piOOE 게임 (APIO22_game) C++17
60 / 100
4000 ms 41908 KB
#include "game.h"
#include <bits/stdc++.h>

constexpr int N = 3e5 + 7, B = 8, inf = 1e9 + 7;

int fromMe[N], toMe[N], save[N][2], n, k; //smallest from me, biggest to me

std::vector<int> adj[N], rev[N];

bool found = false;

void init(int n, int k) {
    ::n = n, ::k = k;

    for (int i = 0; i < n; ++i) {
        if (i >= k) {
            fromMe[i] = inf, toMe[i] = -inf;
        } else {
            fromMe[i] = toMe[i] = i;
        }

        save[i][0] = inf, save[i][1] = -inf;
    }
}

void dfs2(int v, int x);

void dfs1(int v, int x) {
    if (found || v < k || fromMe[v] <= x) {
        return;
    }

    if ((fromMe[v] >> B != toMe[v] >> B) && (fromMe[v] >> B) <= (x >> B)) {
        save[v][0] = std::min(save[v][0], x);
        return;
    }

    fromMe[v] = x;

    if (fromMe[v] <= toMe[v]) {
        found = true;
        return;
    }

    if ((toMe[v] >> B) == (fromMe[v] >> B)) {
        if (save[v][1] >= 0) {
            int s = save[v][1];
            save[v][1] = -1;
            dfs2(v, s);
        }
    }

    for (int to : rev[v]) {
        dfs1(to, x);
    }
}

void dfs2(int v, int x) {
    if (found || v < k || toMe[v] >= x) {
        return;
    }

    if ((fromMe[v] >> B) != (toMe[v] >> B) && (toMe[v] >> B) >= (x >> B)) {
//        save[v][1] = std::max(save[v][1], x);
        return;
    }

    toMe[v] = x;

    if (fromMe[v] <= toMe[v]) {
        found = true;
        return;
    }

    if ((toMe[v] >> B) == (fromMe[v] >> B)) {
        if (save[v][0] <= k) {
            int s = save[v][0];
            save[v][0] = k + 1;
            dfs1(v, s);
        }
    }

    for (int to : adj[v]) {
        dfs2(to, x);
    }
}

int add_teleporter(int u, int v) {
    if (u < k && v < k && u >= v) {
        return 1;
    }

    adj[u].push_back(v);
    rev[v].push_back(u);

    dfs1(u, fromMe[v]);
    dfs2(v, toMe[u]);

    return found;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14416 KB Output is correct
2 Correct 10 ms 14288 KB Output is correct
3 Correct 8 ms 14424 KB Output is correct
4 Correct 7 ms 14416 KB Output is correct
5 Correct 7 ms 14416 KB Output is correct
6 Correct 7 ms 14416 KB Output is correct
7 Correct 7 ms 14416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14416 KB Output is correct
2 Correct 10 ms 14288 KB Output is correct
3 Correct 8 ms 14424 KB Output is correct
4 Correct 7 ms 14416 KB Output is correct
5 Correct 7 ms 14416 KB Output is correct
6 Correct 7 ms 14416 KB Output is correct
7 Correct 7 ms 14416 KB Output is correct
8 Correct 7 ms 14416 KB Output is correct
9 Correct 8 ms 14288 KB Output is correct
10 Correct 8 ms 14416 KB Output is correct
11 Correct 7 ms 14416 KB Output is correct
12 Correct 8 ms 14416 KB Output is correct
13 Correct 8 ms 14416 KB Output is correct
14 Correct 8 ms 14416 KB Output is correct
15 Correct 8 ms 14416 KB Output is correct
16 Correct 8 ms 14416 KB Output is correct
17 Correct 8 ms 14416 KB Output is correct
18 Correct 9 ms 14340 KB Output is correct
19 Correct 7 ms 14416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14416 KB Output is correct
2 Correct 10 ms 14288 KB Output is correct
3 Correct 8 ms 14424 KB Output is correct
4 Correct 7 ms 14416 KB Output is correct
5 Correct 7 ms 14416 KB Output is correct
6 Correct 7 ms 14416 KB Output is correct
7 Correct 7 ms 14416 KB Output is correct
8 Correct 7 ms 14416 KB Output is correct
9 Correct 8 ms 14288 KB Output is correct
10 Correct 8 ms 14416 KB Output is correct
11 Correct 7 ms 14416 KB Output is correct
12 Correct 8 ms 14416 KB Output is correct
13 Correct 8 ms 14416 KB Output is correct
14 Correct 8 ms 14416 KB Output is correct
15 Correct 8 ms 14416 KB Output is correct
16 Correct 8 ms 14416 KB Output is correct
17 Correct 8 ms 14416 KB Output is correct
18 Correct 9 ms 14340 KB Output is correct
19 Correct 7 ms 14416 KB Output is correct
20 Correct 8 ms 14380 KB Output is correct
21 Correct 8 ms 14416 KB Output is correct
22 Correct 9 ms 14432 KB Output is correct
23 Correct 9 ms 14436 KB Output is correct
24 Correct 8 ms 14488 KB Output is correct
25 Correct 10 ms 14416 KB Output is correct
26 Correct 10 ms 14416 KB Output is correct
27 Correct 10 ms 14416 KB Output is correct
28 Correct 10 ms 14360 KB Output is correct
29 Correct 9 ms 14416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14416 KB Output is correct
2 Correct 10 ms 14288 KB Output is correct
3 Correct 8 ms 14424 KB Output is correct
4 Correct 7 ms 14416 KB Output is correct
5 Correct 7 ms 14416 KB Output is correct
6 Correct 7 ms 14416 KB Output is correct
7 Correct 7 ms 14416 KB Output is correct
8 Correct 7 ms 14416 KB Output is correct
9 Correct 8 ms 14288 KB Output is correct
10 Correct 8 ms 14416 KB Output is correct
11 Correct 7 ms 14416 KB Output is correct
12 Correct 8 ms 14416 KB Output is correct
13 Correct 8 ms 14416 KB Output is correct
14 Correct 8 ms 14416 KB Output is correct
15 Correct 8 ms 14416 KB Output is correct
16 Correct 8 ms 14416 KB Output is correct
17 Correct 8 ms 14416 KB Output is correct
18 Correct 9 ms 14340 KB Output is correct
19 Correct 7 ms 14416 KB Output is correct
20 Correct 8 ms 14380 KB Output is correct
21 Correct 8 ms 14416 KB Output is correct
22 Correct 9 ms 14432 KB Output is correct
23 Correct 9 ms 14436 KB Output is correct
24 Correct 8 ms 14488 KB Output is correct
25 Correct 10 ms 14416 KB Output is correct
26 Correct 10 ms 14416 KB Output is correct
27 Correct 10 ms 14416 KB Output is correct
28 Correct 10 ms 14360 KB Output is correct
29 Correct 9 ms 14416 KB Output is correct
30 Correct 30 ms 15988 KB Output is correct
31 Correct 11 ms 15184 KB Output is correct
32 Correct 26 ms 16868 KB Output is correct
33 Correct 22 ms 16664 KB Output is correct
34 Correct 42 ms 17604 KB Output is correct
35 Correct 42 ms 17072 KB Output is correct
36 Correct 39 ms 16656 KB Output is correct
37 Correct 33 ms 16696 KB Output is correct
38 Correct 37 ms 16560 KB Output is correct
39 Correct 35 ms 16468 KB Output is correct
40 Correct 57 ms 17724 KB Output is correct
41 Correct 43 ms 16728 KB Output is correct
42 Correct 41 ms 16556 KB Output is correct
43 Correct 41 ms 17224 KB Output is correct
44 Correct 120 ms 17572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14416 KB Output is correct
2 Correct 10 ms 14288 KB Output is correct
3 Correct 8 ms 14424 KB Output is correct
4 Correct 7 ms 14416 KB Output is correct
5 Correct 7 ms 14416 KB Output is correct
6 Correct 7 ms 14416 KB Output is correct
7 Correct 7 ms 14416 KB Output is correct
8 Correct 7 ms 14416 KB Output is correct
9 Correct 8 ms 14288 KB Output is correct
10 Correct 8 ms 14416 KB Output is correct
11 Correct 7 ms 14416 KB Output is correct
12 Correct 8 ms 14416 KB Output is correct
13 Correct 8 ms 14416 KB Output is correct
14 Correct 8 ms 14416 KB Output is correct
15 Correct 8 ms 14416 KB Output is correct
16 Correct 8 ms 14416 KB Output is correct
17 Correct 8 ms 14416 KB Output is correct
18 Correct 9 ms 14340 KB Output is correct
19 Correct 7 ms 14416 KB Output is correct
20 Correct 8 ms 14380 KB Output is correct
21 Correct 8 ms 14416 KB Output is correct
22 Correct 9 ms 14432 KB Output is correct
23 Correct 9 ms 14436 KB Output is correct
24 Correct 8 ms 14488 KB Output is correct
25 Correct 10 ms 14416 KB Output is correct
26 Correct 10 ms 14416 KB Output is correct
27 Correct 10 ms 14416 KB Output is correct
28 Correct 10 ms 14360 KB Output is correct
29 Correct 9 ms 14416 KB Output is correct
30 Correct 30 ms 15988 KB Output is correct
31 Correct 11 ms 15184 KB Output is correct
32 Correct 26 ms 16868 KB Output is correct
33 Correct 22 ms 16664 KB Output is correct
34 Correct 42 ms 17604 KB Output is correct
35 Correct 42 ms 17072 KB Output is correct
36 Correct 39 ms 16656 KB Output is correct
37 Correct 33 ms 16696 KB Output is correct
38 Correct 37 ms 16560 KB Output is correct
39 Correct 35 ms 16468 KB Output is correct
40 Correct 57 ms 17724 KB Output is correct
41 Correct 43 ms 16728 KB Output is correct
42 Correct 41 ms 16556 KB Output is correct
43 Correct 41 ms 17224 KB Output is correct
44 Correct 120 ms 17572 KB Output is correct
45 Correct 262 ms 30388 KB Output is correct
46 Correct 14 ms 19536 KB Output is correct
47 Correct 16 ms 19340 KB Output is correct
48 Correct 302 ms 41908 KB Output is correct
49 Correct 262 ms 37812 KB Output is correct
50 Execution timed out 4065 ms 34612 KB Time limit exceeded
51 Halted 0 ms 0 KB -