Submission #578277

# Submission time Handle Problem Language Result Execution time Memory
578277 2022-06-16T10:02:36 Z nonsensenonsense1 Game (APIO22_game) C++17
0 / 100
9 ms 14416 KB
#include "game.h"
#include <bits/stdc++.h>
#define ll long long

#define N 300000
#define L 19
bool left[L][N], right[L][N], done;
std::vector<int> g[N], gg[N];
int k;

void build(int l, int r, int lvl) {
  int m = l + r >> 1;
  for (int i = l; i <= m; ++i)
    left[lvl][i] = 1;
  for (int i = m; i < r; ++i)
    right[lvl][i] = 1;
  if (l < m)
    build(l, m, lvl + 1);
  if (m + 1 < r)
    build(m + 1, r, lvl + 1);
}

void init(int n, int k_) {
  k = k_;
  build(0, k, 0);
}

int mid;

void addright(int v, int lvl) {
  if (right[lvl][v])
    return;
  right[lvl][v] = 1;
  if (v != mid && left[lvl][v])
    done = 1;
  for (int i = 0; i < (int)g[v].size(); ++i)
    addright(g[v][i], lvl);
}

void addleft(int v, int lvl) {
  if (left[lvl][v])
    return;
  left[lvl][v] = 1;
  if (v != mid && right[lvl][v])
    done = 1;
  for (int i = 0; i < (int)gg[v].size(); ++i)
    addleft(gg[v][i], lvl);
}

void run(int l, int r, int u, int v, int lvl) {
  int m = l + r >> 1;
  mid = m;
  if (right[lvl][u])
    addright(v, lvl);
  if (left[lvl][v])
    addleft(u, lvl);
  if (m + 1 < r && !done && right[lvl][u] && right[lvl][v])
    run(m + 1, r, u, v, lvl + 1);
  if (l < m && !done && left[lvl][u] && left[lvl][v])
    run(l, m, u, v, lvl + 1);
}

int add_teleporter(int u, int v) {
  if (u == v && u < k)
    return 1;
  g[u].push_back(v);
  gg[v].push_back(u);
  run(0, k, u, v, 0);
  return done;
}

Compilation message

game.cpp: In function 'void build(int, int, int)':
game.cpp:12:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   12 |   int m = l + r >> 1;
      |           ~~^~~
game.cpp: In function 'void run(int, int, int, int, int)':
game.cpp:51:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   51 |   int m = l + r >> 1;
      |           ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14288 KB Output is correct
2 Incorrect 8 ms 14416 KB Wrong Answer[1]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14288 KB Output is correct
2 Incorrect 8 ms 14416 KB Wrong Answer[1]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14288 KB Output is correct
2 Incorrect 8 ms 14416 KB Wrong Answer[1]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14288 KB Output is correct
2 Incorrect 8 ms 14416 KB Wrong Answer[1]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14288 KB Output is correct
2 Incorrect 8 ms 14416 KB Wrong Answer[1]
3 Halted 0 ms 0 KB -