Submission #964061

# Submission time Handle Problem Language Result Execution time Memory
964061 2024-04-16T09:08:50 Z kilkuwu Game (APIO22_game) C++17
100 / 100
1690 ms 68108 KB
#include "game.h"

#include <bits/stdc++.h>

int n, k;

constexpr int N = 3e5 + 5;

int lb[N], rb[N];

std::vector<int> adj[N];
std::vector<int> radj[N];

void add_edge(int u, int v) {
  adj[u].push_back(v);
  radj[v].push_back(u);
}

void init(int _n, int _k) {
  n = _n + 1;
  k = _k;
  for (int i = 1; i <= n; i++) {
    lb[i] = 0;
    rb[i] = k + 1;
  }
  for (int i = 1; i <= k; i++) {
    lb[i] = i;
    rb[i] = i;
  }
  for (int i = 1; i + 1 <= k; i++) {
    add_edge(i, i + 1);
  }
}

bool update_edge(int, int);

bool update_vertex(int u) {
  for (int v : adj[u]) {
    if (update_edge(u, v)) return true;
  }
  for (int v : radj[u]) {
    if (update_edge(v, u)) return true;
  }
  return false;
}

bool update_edge(int u, int v) {
  int be_reached_min_u = lb[u];
  int be_reached_max_u = u <= k ? rb[u] : rb[u] - 1;
  int can_reach_min_v = v <= k ? lb[v] : lb[v] + 1;
  int can_reach_max_v = rb[v];

  // std::cerr << u << " " << v << std::endl;
  // std::cerr << be_reached_min_u << " " << be_reached_max_u << " " << can_reach_max_v << " " << can_reach_min_v << std::endl;

  if (be_reached_min_u >= can_reach_max_v) {
    return true;
  }

  if (be_reached_max_u < can_reach_min_v) {
    return false;
  }

  if ((lb[v] + rb[v]) / 2 + 1 <= be_reached_min_u) {
    // we can shift it to the right
    int m = (lb[v] + rb[v]) / 2;
    while (m + 1 <= be_reached_min_u) {
      lb[v] = m + 1;
      m = (lb[v] + rb[v]) / 2;
    }
    
    if (update_vertex(v)) return true;
  }

  if ((lb[u] + rb[u]) / 2 >= can_reach_max_v) {
    int m = (lb[u] + rb[u]) / 2;
    while (m >= can_reach_max_v) {
      rb[u] = m;
      m = (lb[u] + rb[u]) / 2;
    }
    if (update_vertex(u)) return true;
  }

  return false;
}

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

  if (v <= u && u <= k) { // eliminates
    return 1;
  }

  add_edge(u, v);
  return update_edge(u, v);
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14936 KB Output is correct
2 Correct 3 ms 14936 KB Output is correct
3 Correct 3 ms 14936 KB Output is correct
4 Correct 5 ms 15116 KB Output is correct
5 Correct 3 ms 14936 KB Output is correct
6 Correct 4 ms 14964 KB Output is correct
7 Correct 3 ms 14936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14936 KB Output is correct
2 Correct 3 ms 14936 KB Output is correct
3 Correct 3 ms 14936 KB Output is correct
4 Correct 5 ms 15116 KB Output is correct
5 Correct 3 ms 14936 KB Output is correct
6 Correct 4 ms 14964 KB Output is correct
7 Correct 3 ms 14936 KB Output is correct
8 Correct 3 ms 14936 KB Output is correct
9 Correct 4 ms 14936 KB Output is correct
10 Correct 3 ms 14936 KB Output is correct
11 Correct 3 ms 14936 KB Output is correct
12 Correct 3 ms 14768 KB Output is correct
13 Correct 3 ms 14936 KB Output is correct
14 Correct 3 ms 14936 KB Output is correct
15 Correct 3 ms 14936 KB Output is correct
16 Correct 5 ms 15192 KB Output is correct
17 Correct 4 ms 14936 KB Output is correct
18 Correct 3 ms 14936 KB Output is correct
19 Correct 4 ms 14936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14936 KB Output is correct
2 Correct 3 ms 14936 KB Output is correct
3 Correct 3 ms 14936 KB Output is correct
4 Correct 5 ms 15116 KB Output is correct
5 Correct 3 ms 14936 KB Output is correct
6 Correct 4 ms 14964 KB Output is correct
7 Correct 3 ms 14936 KB Output is correct
8 Correct 3 ms 14936 KB Output is correct
9 Correct 4 ms 14936 KB Output is correct
10 Correct 3 ms 14936 KB Output is correct
11 Correct 3 ms 14936 KB Output is correct
12 Correct 3 ms 14768 KB Output is correct
13 Correct 3 ms 14936 KB Output is correct
14 Correct 3 ms 14936 KB Output is correct
15 Correct 3 ms 14936 KB Output is correct
16 Correct 5 ms 15192 KB Output is correct
17 Correct 4 ms 14936 KB Output is correct
18 Correct 3 ms 14936 KB Output is correct
19 Correct 4 ms 14936 KB Output is correct
20 Correct 4 ms 15192 KB Output is correct
21 Correct 3 ms 14936 KB Output is correct
22 Correct 3 ms 14936 KB Output is correct
23 Correct 4 ms 15192 KB Output is correct
24 Correct 4 ms 14936 KB Output is correct
25 Correct 5 ms 15192 KB Output is correct
26 Correct 6 ms 15192 KB Output is correct
27 Correct 5 ms 15192 KB Output is correct
28 Correct 4 ms 15192 KB Output is correct
29 Correct 4 ms 15024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14936 KB Output is correct
2 Correct 3 ms 14936 KB Output is correct
3 Correct 3 ms 14936 KB Output is correct
4 Correct 5 ms 15116 KB Output is correct
5 Correct 3 ms 14936 KB Output is correct
6 Correct 4 ms 14964 KB Output is correct
7 Correct 3 ms 14936 KB Output is correct
8 Correct 3 ms 14936 KB Output is correct
9 Correct 4 ms 14936 KB Output is correct
10 Correct 3 ms 14936 KB Output is correct
11 Correct 3 ms 14936 KB Output is correct
12 Correct 3 ms 14768 KB Output is correct
13 Correct 3 ms 14936 KB Output is correct
14 Correct 3 ms 14936 KB Output is correct
15 Correct 3 ms 14936 KB Output is correct
16 Correct 5 ms 15192 KB Output is correct
17 Correct 4 ms 14936 KB Output is correct
18 Correct 3 ms 14936 KB Output is correct
19 Correct 4 ms 14936 KB Output is correct
20 Correct 4 ms 15192 KB Output is correct
21 Correct 3 ms 14936 KB Output is correct
22 Correct 3 ms 14936 KB Output is correct
23 Correct 4 ms 15192 KB Output is correct
24 Correct 4 ms 14936 KB Output is correct
25 Correct 5 ms 15192 KB Output is correct
26 Correct 6 ms 15192 KB Output is correct
27 Correct 5 ms 15192 KB Output is correct
28 Correct 4 ms 15192 KB Output is correct
29 Correct 4 ms 15024 KB Output is correct
30 Correct 18 ms 17172 KB Output is correct
31 Correct 8 ms 15704 KB Output is correct
32 Correct 20 ms 17980 KB Output is correct
33 Correct 18 ms 17468 KB Output is correct
34 Correct 30 ms 21052 KB Output is correct
35 Correct 32 ms 18704 KB Output is correct
36 Correct 36 ms 17652 KB Output is correct
37 Correct 30 ms 17304 KB Output is correct
38 Correct 27 ms 17252 KB Output is correct
39 Correct 34 ms 17484 KB Output is correct
40 Correct 28 ms 19980 KB Output is correct
41 Correct 32 ms 18164 KB Output is correct
42 Correct 30 ms 17736 KB Output is correct
43 Correct 38 ms 18544 KB Output is correct
44 Correct 52 ms 18300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14936 KB Output is correct
2 Correct 3 ms 14936 KB Output is correct
3 Correct 3 ms 14936 KB Output is correct
4 Correct 5 ms 15116 KB Output is correct
5 Correct 3 ms 14936 KB Output is correct
6 Correct 4 ms 14964 KB Output is correct
7 Correct 3 ms 14936 KB Output is correct
8 Correct 3 ms 14936 KB Output is correct
9 Correct 4 ms 14936 KB Output is correct
10 Correct 3 ms 14936 KB Output is correct
11 Correct 3 ms 14936 KB Output is correct
12 Correct 3 ms 14768 KB Output is correct
13 Correct 3 ms 14936 KB Output is correct
14 Correct 3 ms 14936 KB Output is correct
15 Correct 3 ms 14936 KB Output is correct
16 Correct 5 ms 15192 KB Output is correct
17 Correct 4 ms 14936 KB Output is correct
18 Correct 3 ms 14936 KB Output is correct
19 Correct 4 ms 14936 KB Output is correct
20 Correct 4 ms 15192 KB Output is correct
21 Correct 3 ms 14936 KB Output is correct
22 Correct 3 ms 14936 KB Output is correct
23 Correct 4 ms 15192 KB Output is correct
24 Correct 4 ms 14936 KB Output is correct
25 Correct 5 ms 15192 KB Output is correct
26 Correct 6 ms 15192 KB Output is correct
27 Correct 5 ms 15192 KB Output is correct
28 Correct 4 ms 15192 KB Output is correct
29 Correct 4 ms 15024 KB Output is correct
30 Correct 18 ms 17172 KB Output is correct
31 Correct 8 ms 15704 KB Output is correct
32 Correct 20 ms 17980 KB Output is correct
33 Correct 18 ms 17468 KB Output is correct
34 Correct 30 ms 21052 KB Output is correct
35 Correct 32 ms 18704 KB Output is correct
36 Correct 36 ms 17652 KB Output is correct
37 Correct 30 ms 17304 KB Output is correct
38 Correct 27 ms 17252 KB Output is correct
39 Correct 34 ms 17484 KB Output is correct
40 Correct 28 ms 19980 KB Output is correct
41 Correct 32 ms 18164 KB Output is correct
42 Correct 30 ms 17736 KB Output is correct
43 Correct 38 ms 18544 KB Output is correct
44 Correct 52 ms 18300 KB Output is correct
45 Correct 206 ms 28812 KB Output is correct
46 Correct 7 ms 17240 KB Output is correct
47 Correct 8 ms 18008 KB Output is correct
48 Correct 349 ms 47776 KB Output is correct
49 Correct 224 ms 35840 KB Output is correct
50 Correct 583 ms 57600 KB Output is correct
51 Correct 871 ms 47228 KB Output is correct
52 Correct 564 ms 35888 KB Output is correct
53 Correct 797 ms 36176 KB Output is correct
54 Correct 785 ms 35936 KB Output is correct
55 Correct 1239 ms 36852 KB Output is correct
56 Correct 1539 ms 36480 KB Output is correct
57 Correct 439 ms 36448 KB Output is correct
58 Correct 482 ms 36440 KB Output is correct
59 Correct 445 ms 36200 KB Output is correct
60 Correct 638 ms 37232 KB Output is correct
61 Correct 710 ms 36636 KB Output is correct
62 Correct 447 ms 43340 KB Output is correct
63 Correct 392 ms 40356 KB Output is correct
64 Correct 1319 ms 68108 KB Output is correct
65 Correct 487 ms 37552 KB Output is correct
66 Correct 487 ms 33704 KB Output is correct
67 Correct 703 ms 44120 KB Output is correct
68 Correct 194 ms 30396 KB Output is correct
69 Correct 52 ms 24280 KB Output is correct
70 Correct 863 ms 46244 KB Output is correct
71 Correct 308 ms 30436 KB Output is correct
72 Correct 207 ms 26280 KB Output is correct
73 Correct 623 ms 41388 KB Output is correct
74 Correct 1690 ms 36712 KB Output is correct
75 Correct 1081 ms 50240 KB Output is correct
76 Correct 1179 ms 53732 KB Output is correct