Submission #964048

# Submission time Handle Problem Language Result Execution time Memory
964048 2024-04-16T08:55:17 Z kilkuwu Game (APIO22_game) C++17
2 / 100
5 ms 14976 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];

  if (be_reached_min_u >= can_reach_max_v) {
    // this surely works
    return true;
  }

  if (be_reached_max_u <= can_reach_min_v) {
    // this can never cross anymore
    return false;
  }

  // now they are somewhat in the middle

  // we have to update be_reach_v
  // be_reach_v must be >= be_reach_min_u

  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 3 ms 14936 KB Output is correct
5 Correct 4 ms 14936 KB Output is correct
6 Correct 3 ms 14768 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 3 ms 14936 KB Output is correct
5 Correct 4 ms 14936 KB Output is correct
6 Correct 3 ms 14768 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 4 ms 14936 KB Output is correct
11 Correct 3 ms 14936 KB Output is correct
12 Correct 3 ms 14936 KB Output is correct
13 Incorrect 5 ms 14976 KB Wrong Answer[1]
14 Halted 0 ms 0 KB -
# 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 3 ms 14936 KB Output is correct
5 Correct 4 ms 14936 KB Output is correct
6 Correct 3 ms 14768 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 4 ms 14936 KB Output is correct
11 Correct 3 ms 14936 KB Output is correct
12 Correct 3 ms 14936 KB Output is correct
13 Incorrect 5 ms 14976 KB Wrong Answer[1]
14 Halted 0 ms 0 KB -
# 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 3 ms 14936 KB Output is correct
5 Correct 4 ms 14936 KB Output is correct
6 Correct 3 ms 14768 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 4 ms 14936 KB Output is correct
11 Correct 3 ms 14936 KB Output is correct
12 Correct 3 ms 14936 KB Output is correct
13 Incorrect 5 ms 14976 KB Wrong Answer[1]
14 Halted 0 ms 0 KB -
# 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 3 ms 14936 KB Output is correct
5 Correct 4 ms 14936 KB Output is correct
6 Correct 3 ms 14768 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 4 ms 14936 KB Output is correct
11 Correct 3 ms 14936 KB Output is correct
12 Correct 3 ms 14936 KB Output is correct
13 Incorrect 5 ms 14976 KB Wrong Answer[1]
14 Halted 0 ms 0 KB -