Submission #575931

# Submission time Handle Problem Language Result Execution time Memory
575931 2022-06-11T20:59:36 Z SHZhang Game (APIO22_game) C++17
60 / 100
1293 ms 3960 KB
#include "game.h"
#include <queue>
#include <vector>

using namespace std;

vector<int> graph[30005];
vector<int> rgraph[30005];
int n, k;

int first_go[30005], last_come[30005];

int finish = 0;

queue<int> que;

bool inque[30005];

void push_queue(int x)
{
    if (!inque[x]) {
        que.push(x); inque[x] = true;
    }
}

int pop_queue()
{
    int res = que.front(); que.pop();
    inque[res] = false;
    return res;
}

void init(int N, int K) {
    n = N; k = K;
    for (int i = 0; i < n; i++) {
        first_go[i] = n;
        last_come[i] = -1;
    }
    for (int i = 0; i + 1 < k; i++) {
        graph[i].push_back(i+1);
        rgraph[i+1].push_back(i);
    }
    for (int i = 0; i < k; i++) {
        first_go[i] = last_come[i] = i;
    }
}

int add_teleporter(int u, int v) {
    if (v <= u && u < k) return 1;
    graph[u].push_back(v);
    rgraph[v].push_back(u);
    push_queue(u);
    push_queue(v);
    while (!que.empty()) {
        int node = pop_queue();
        int old_first_go = first_go[node];
        for (int i = 0; i < graph[node].size(); i++) {
            int nxt = graph[node][i];
            first_go[node] = min(first_go[node], first_go[nxt]);
        }
        if (old_first_go != first_go[node]) {
            for (int i = 0; i < rgraph[node].size(); i++) {
                int nxt = rgraph[node][i];
                push_queue(nxt);
            }
        }
        int old_last_come = last_come[node];
        for (int i = 0; i < rgraph[node].size(); i++) {
            int nxt = rgraph[node][i];
            last_come[node] = max(last_come[node], last_come[nxt]);
        }
        if (old_last_come != last_come[node]) {
            for (int i = 0; i < graph[node].size(); i++) {
                int nxt = graph[node][i];
                push_queue(nxt);
            }
        }
        if (node >= k && first_go[node] <= last_come[node]) finish = 1;
    }
    return finish;
}

Compilation message

game.cpp: In function 'int add_teleporter(int, int)':
game.cpp:57:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |         for (int i = 0; i < graph[node].size(); i++) {
      |                         ~~^~~~~~~~~~~~~~~~~~~~
game.cpp:62:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |             for (int i = 0; i < rgraph[node].size(); i++) {
      |                             ~~^~~~~~~~~~~~~~~~~~~~~
game.cpp:68:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |         for (int i = 0; i < rgraph[node].size(); i++) {
      |                         ~~^~~~~~~~~~~~~~~~~~~~~
game.cpp:73:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |             for (int i = 0; i < graph[node].size(); i++) {
      |                             ~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1616 KB Output is correct
2 Correct 1 ms 1616 KB Output is correct
3 Correct 1 ms 1716 KB Output is correct
4 Correct 1 ms 1616 KB Output is correct
5 Correct 1 ms 1616 KB Output is correct
6 Correct 1 ms 1616 KB Output is correct
7 Correct 1 ms 1616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1616 KB Output is correct
2 Correct 1 ms 1616 KB Output is correct
3 Correct 1 ms 1716 KB Output is correct
4 Correct 1 ms 1616 KB Output is correct
5 Correct 1 ms 1616 KB Output is correct
6 Correct 1 ms 1616 KB Output is correct
7 Correct 1 ms 1616 KB Output is correct
8 Correct 1 ms 1616 KB Output is correct
9 Correct 1 ms 1616 KB Output is correct
10 Correct 1 ms 1616 KB Output is correct
11 Correct 1 ms 1616 KB Output is correct
12 Correct 1 ms 1616 KB Output is correct
13 Correct 1 ms 1664 KB Output is correct
14 Correct 1 ms 1616 KB Output is correct
15 Correct 1 ms 1616 KB Output is correct
16 Correct 1 ms 1616 KB Output is correct
17 Correct 1 ms 1616 KB Output is correct
18 Correct 1 ms 1616 KB Output is correct
19 Correct 1 ms 1616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1616 KB Output is correct
2 Correct 1 ms 1616 KB Output is correct
3 Correct 1 ms 1716 KB Output is correct
4 Correct 1 ms 1616 KB Output is correct
5 Correct 1 ms 1616 KB Output is correct
6 Correct 1 ms 1616 KB Output is correct
7 Correct 1 ms 1616 KB Output is correct
8 Correct 1 ms 1616 KB Output is correct
9 Correct 1 ms 1616 KB Output is correct
10 Correct 1 ms 1616 KB Output is correct
11 Correct 1 ms 1616 KB Output is correct
12 Correct 1 ms 1616 KB Output is correct
13 Correct 1 ms 1664 KB Output is correct
14 Correct 1 ms 1616 KB Output is correct
15 Correct 1 ms 1616 KB Output is correct
16 Correct 1 ms 1616 KB Output is correct
17 Correct 1 ms 1616 KB Output is correct
18 Correct 1 ms 1616 KB Output is correct
19 Correct 1 ms 1616 KB Output is correct
20 Correct 1 ms 1744 KB Output is correct
21 Correct 1 ms 1616 KB Output is correct
22 Correct 2 ms 1744 KB Output is correct
23 Correct 1 ms 1744 KB Output is correct
24 Correct 8 ms 1780 KB Output is correct
25 Correct 5 ms 1744 KB Output is correct
26 Correct 4 ms 1744 KB Output is correct
27 Correct 5 ms 1800 KB Output is correct
28 Correct 2 ms 1744 KB Output is correct
29 Correct 4 ms 1780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1616 KB Output is correct
2 Correct 1 ms 1616 KB Output is correct
3 Correct 1 ms 1716 KB Output is correct
4 Correct 1 ms 1616 KB Output is correct
5 Correct 1 ms 1616 KB Output is correct
6 Correct 1 ms 1616 KB Output is correct
7 Correct 1 ms 1616 KB Output is correct
8 Correct 1 ms 1616 KB Output is correct
9 Correct 1 ms 1616 KB Output is correct
10 Correct 1 ms 1616 KB Output is correct
11 Correct 1 ms 1616 KB Output is correct
12 Correct 1 ms 1616 KB Output is correct
13 Correct 1 ms 1664 KB Output is correct
14 Correct 1 ms 1616 KB Output is correct
15 Correct 1 ms 1616 KB Output is correct
16 Correct 1 ms 1616 KB Output is correct
17 Correct 1 ms 1616 KB Output is correct
18 Correct 1 ms 1616 KB Output is correct
19 Correct 1 ms 1616 KB Output is correct
20 Correct 1 ms 1744 KB Output is correct
21 Correct 1 ms 1616 KB Output is correct
22 Correct 2 ms 1744 KB Output is correct
23 Correct 1 ms 1744 KB Output is correct
24 Correct 8 ms 1780 KB Output is correct
25 Correct 5 ms 1744 KB Output is correct
26 Correct 4 ms 1744 KB Output is correct
27 Correct 5 ms 1800 KB Output is correct
28 Correct 2 ms 1744 KB Output is correct
29 Correct 4 ms 1780 KB Output is correct
30 Correct 16 ms 3108 KB Output is correct
31 Correct 5 ms 2340 KB Output is correct
32 Correct 18 ms 3696 KB Output is correct
33 Correct 17 ms 3784 KB Output is correct
34 Correct 1167 ms 3960 KB Output is correct
35 Correct 492 ms 3928 KB Output is correct
36 Correct 38 ms 3724 KB Output is correct
37 Correct 34 ms 3784 KB Output is correct
38 Correct 30 ms 3576 KB Output is correct
39 Correct 33 ms 3540 KB Output is correct
40 Correct 937 ms 3960 KB Output is correct
41 Correct 187 ms 3616 KB Output is correct
42 Correct 123 ms 3624 KB Output is correct
43 Correct 50 ms 3932 KB Output is correct
44 Correct 1293 ms 3872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1616 KB Output is correct
2 Correct 1 ms 1616 KB Output is correct
3 Correct 1 ms 1716 KB Output is correct
4 Correct 1 ms 1616 KB Output is correct
5 Correct 1 ms 1616 KB Output is correct
6 Correct 1 ms 1616 KB Output is correct
7 Correct 1 ms 1616 KB Output is correct
8 Correct 1 ms 1616 KB Output is correct
9 Correct 1 ms 1616 KB Output is correct
10 Correct 1 ms 1616 KB Output is correct
11 Correct 1 ms 1616 KB Output is correct
12 Correct 1 ms 1616 KB Output is correct
13 Correct 1 ms 1664 KB Output is correct
14 Correct 1 ms 1616 KB Output is correct
15 Correct 1 ms 1616 KB Output is correct
16 Correct 1 ms 1616 KB Output is correct
17 Correct 1 ms 1616 KB Output is correct
18 Correct 1 ms 1616 KB Output is correct
19 Correct 1 ms 1616 KB Output is correct
20 Correct 1 ms 1744 KB Output is correct
21 Correct 1 ms 1616 KB Output is correct
22 Correct 2 ms 1744 KB Output is correct
23 Correct 1 ms 1744 KB Output is correct
24 Correct 8 ms 1780 KB Output is correct
25 Correct 5 ms 1744 KB Output is correct
26 Correct 4 ms 1744 KB Output is correct
27 Correct 5 ms 1800 KB Output is correct
28 Correct 2 ms 1744 KB Output is correct
29 Correct 4 ms 1780 KB Output is correct
30 Correct 16 ms 3108 KB Output is correct
31 Correct 5 ms 2340 KB Output is correct
32 Correct 18 ms 3696 KB Output is correct
33 Correct 17 ms 3784 KB Output is correct
34 Correct 1167 ms 3960 KB Output is correct
35 Correct 492 ms 3928 KB Output is correct
36 Correct 38 ms 3724 KB Output is correct
37 Correct 34 ms 3784 KB Output is correct
38 Correct 30 ms 3576 KB Output is correct
39 Correct 33 ms 3540 KB Output is correct
40 Correct 937 ms 3960 KB Output is correct
41 Correct 187 ms 3616 KB Output is correct
42 Correct 123 ms 3624 KB Output is correct
43 Correct 50 ms 3932 KB Output is correct
44 Correct 1293 ms 3872 KB Output is correct
45 Runtime error 3 ms 3600 KB Execution killed with signal 11
46 Halted 0 ms 0 KB -