Submission #897199

# Submission time Handle Problem Language Result Execution time Memory
897199 2024-01-02T17:24:57 Z d4xn Game (APIO22_game) C++17
60 / 100
2512 ms 29756 KB
#include <bits/stdc++.h>
#include "game.h"

using namespace std;

const int N = 3e4+4, K = 1e3+3, inf = INT_MAX;

bool cycle;
int n, k, mn[K];
bitset<N> bt[K];
vector<int> adj[N];

void dfs(int x, int y) {
  if (bt[x][y]) return;
  bt[x][y] = 1;
  mn[x] = min(mn[x], y);

  for (int& z : adj[y]) {
    if (bt[x][z]) continue;
    dfs(x, z);
  }
}

void init(int N, int K) {
  n = N;
  k = K;
  cycle = 0;

  for (int i = 0; i < n; i++) {
    adj[i].clear();
  }

  for (int i = 0; i < k; i++) {
    bt[i].reset();
    mn[i] = (i < k-1 ? k-1 : inf);
  }
}

int add_teleporter(int u, int v) {
  if (cycle) return 1;

  if (u < k && u == v) return cycle = 1;

  adj[u].push_back(v);

  if (u >= k) {
    for (int i = 0; i < k; i++) {
      if (!bt[i][u]) continue;
      adj[i].push_back(v);
      dfs(i, v);
    }
  }
  else if (u < k && v < k) {
    if (u < v) return 0;
    else return cycle = 1;
  }
  else if (u < k) {
    dfs(u, v);
  }

  for (int i = 0; i < k; i++) {
    if (mn[i] <= i) {
      cycle = 1;
      break;
    }
  }
  
  return cycle;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 1 ms 2648 KB Output is correct
6 Correct 1 ms 2648 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 1 ms 2648 KB Output is correct
6 Correct 1 ms 2648 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 1 ms 2648 KB Output is correct
11 Correct 1 ms 2648 KB Output is correct
12 Correct 1 ms 2648 KB Output is correct
13 Correct 1 ms 2648 KB Output is correct
14 Correct 1 ms 2648 KB Output is correct
15 Correct 1 ms 2648 KB Output is correct
16 Correct 1 ms 2648 KB Output is correct
17 Correct 1 ms 2648 KB Output is correct
18 Correct 1 ms 2648 KB Output is correct
19 Correct 1 ms 2648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 1 ms 2648 KB Output is correct
6 Correct 1 ms 2648 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 1 ms 2648 KB Output is correct
11 Correct 1 ms 2648 KB Output is correct
12 Correct 1 ms 2648 KB Output is correct
13 Correct 1 ms 2648 KB Output is correct
14 Correct 1 ms 2648 KB Output is correct
15 Correct 1 ms 2648 KB Output is correct
16 Correct 1 ms 2648 KB Output is correct
17 Correct 1 ms 2648 KB Output is correct
18 Correct 1 ms 2648 KB Output is correct
19 Correct 1 ms 2648 KB Output is correct
20 Correct 1 ms 2648 KB Output is correct
21 Correct 1 ms 2648 KB Output is correct
22 Correct 1 ms 2900 KB Output is correct
23 Correct 1 ms 2648 KB Output is correct
24 Correct 3 ms 4952 KB Output is correct
25 Correct 4 ms 2648 KB Output is correct
26 Correct 4 ms 2904 KB Output is correct
27 Correct 7 ms 4696 KB Output is correct
28 Correct 3 ms 4696 KB Output is correct
29 Correct 4 ms 4952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 1 ms 2648 KB Output is correct
6 Correct 1 ms 2648 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 1 ms 2648 KB Output is correct
11 Correct 1 ms 2648 KB Output is correct
12 Correct 1 ms 2648 KB Output is correct
13 Correct 1 ms 2648 KB Output is correct
14 Correct 1 ms 2648 KB Output is correct
15 Correct 1 ms 2648 KB Output is correct
16 Correct 1 ms 2648 KB Output is correct
17 Correct 1 ms 2648 KB Output is correct
18 Correct 1 ms 2648 KB Output is correct
19 Correct 1 ms 2648 KB Output is correct
20 Correct 1 ms 2648 KB Output is correct
21 Correct 1 ms 2648 KB Output is correct
22 Correct 1 ms 2900 KB Output is correct
23 Correct 1 ms 2648 KB Output is correct
24 Correct 3 ms 4952 KB Output is correct
25 Correct 4 ms 2648 KB Output is correct
26 Correct 4 ms 2904 KB Output is correct
27 Correct 7 ms 4696 KB Output is correct
28 Correct 3 ms 4696 KB Output is correct
29 Correct 4 ms 4952 KB Output is correct
30 Correct 13 ms 3692 KB Output is correct
31 Correct 15 ms 5156 KB Output is correct
32 Correct 15 ms 4184 KB Output is correct
33 Correct 9 ms 3624 KB Output is correct
34 Correct 485 ms 7884 KB Output is correct
35 Correct 397 ms 7964 KB Output is correct
36 Correct 54 ms 4140 KB Output is correct
37 Correct 295 ms 8556 KB Output is correct
38 Correct 247 ms 10780 KB Output is correct
39 Correct 359 ms 12376 KB Output is correct
40 Correct 417 ms 8240 KB Output is correct
41 Correct 183 ms 6744 KB Output is correct
42 Correct 160 ms 6448 KB Output is correct
43 Correct 2512 ms 29756 KB Output is correct
44 Correct 318 ms 8524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 1 ms 2648 KB Output is correct
6 Correct 1 ms 2648 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 1 ms 2648 KB Output is correct
11 Correct 1 ms 2648 KB Output is correct
12 Correct 1 ms 2648 KB Output is correct
13 Correct 1 ms 2648 KB Output is correct
14 Correct 1 ms 2648 KB Output is correct
15 Correct 1 ms 2648 KB Output is correct
16 Correct 1 ms 2648 KB Output is correct
17 Correct 1 ms 2648 KB Output is correct
18 Correct 1 ms 2648 KB Output is correct
19 Correct 1 ms 2648 KB Output is correct
20 Correct 1 ms 2648 KB Output is correct
21 Correct 1 ms 2648 KB Output is correct
22 Correct 1 ms 2900 KB Output is correct
23 Correct 1 ms 2648 KB Output is correct
24 Correct 3 ms 4952 KB Output is correct
25 Correct 4 ms 2648 KB Output is correct
26 Correct 4 ms 2904 KB Output is correct
27 Correct 7 ms 4696 KB Output is correct
28 Correct 3 ms 4696 KB Output is correct
29 Correct 4 ms 4952 KB Output is correct
30 Correct 13 ms 3692 KB Output is correct
31 Correct 15 ms 5156 KB Output is correct
32 Correct 15 ms 4184 KB Output is correct
33 Correct 9 ms 3624 KB Output is correct
34 Correct 485 ms 7884 KB Output is correct
35 Correct 397 ms 7964 KB Output is correct
36 Correct 54 ms 4140 KB Output is correct
37 Correct 295 ms 8556 KB Output is correct
38 Correct 247 ms 10780 KB Output is correct
39 Correct 359 ms 12376 KB Output is correct
40 Correct 417 ms 8240 KB Output is correct
41 Correct 183 ms 6744 KB Output is correct
42 Correct 160 ms 6448 KB Output is correct
43 Correct 2512 ms 29756 KB Output is correct
44 Correct 318 ms 8524 KB Output is correct
45 Runtime error 3 ms 4960 KB Execution killed with signal 11
46 Halted 0 ms 0 KB -