답안 #578332

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
578332 2022-06-16T11:36:06 Z nonsensenonsense1 게임 (APIO22_game) C++17
2 / 100
24 ms 37948 KB
#include "game.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long

#define left dsafh
#define right dslafh

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

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

void init(int n, int k_) {
  memset(ind, -1, sizeof ind);
  k = k_;
  build(0, 0, k, 0);
}

vector<int> ladd, radd;
int top;
void addright(int v, int lvl, int in) {
  if (right[lvl][v])
    return;
  radd.push_back(v);
  ind[lvl + 1][v] = top * 2 + 2;
  right[lvl][v] = 1;
  if (left[lvl][v])
    done = 1;
  for (int i = 0; i < (int)g[v].size(); ++i)
    if (ind[lvl][g[v][i]] == ind[lvl][v])
      addright(g[v][i], lvl, in);
}

void addleft(int v, int lvl, int in) {
  if (left[lvl][v])
    return;
  ladd.push_back(v);
  ind[lvl + 1][v] = top * 1 + 1;
  left[lvl][v] = 1;
  if (right[lvl][v])
    done = 1;
  for (int i = 0; i < (int)gg[v].size(); ++i)
    if (ind[lvl][gg[v][i]] == ind[lvl][v])
      addleft(gg[v][i], lvl, in);
}

void run(int l, int r, int u, int v, bool edg, vector<int> &add, int lvl) {
  if (!edg && add.empty())
    return;
  int m = l + r >> 1;
  ladd.clear();
  radd.clear();
  for (int i = 0; i < (int)add.size(); ++i) {
    int v = add[i];
    for (int j = 0; j < (int)gg[v].size(); ++j)
      if (right[lvl][gg[v][j]] && ind[lvl][gg[v][j]] == ind[lvl][v])
        addright(v, lvl, m);
    for (int j = 0; j < (int)g[v].size(); ++j)
      if (left[lvl][g[v][j]] && ind[lvl][g[v][j]] == ind[lvl][v])
        addleft(v, lvl, m);
  }
  if (edg) {
    if (right[lvl][u])
      addright(v, lvl, m);
    if (left[lvl][v])
      addleft(u, lvl, m);
  }
  vector<int> ladd1 = ladd, radd1 = radd;
  int cur = top;
  if (m + 1 < r) {
    top = cur * 2 + 2;
    run(m + 1, r, u, v,
        u != m && v != m && edg && right[lvl][u] && right[lvl][v], radd1,
        lvl + 1);
  }
  if (l < m) {
    top = cur * 2 + 1;
    run(l, m, u, v, edg && u != m && v != m && left[lvl][u] && left[lvl][v],
        ladd1, 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);
  vector<int> vec;
  top = 0;
  run(0, k, u, v, 1, vec, 0);
  return done;
}

Compilation message

game.cpp: In function 'void build(int, int, int, int)':
game.cpp:17:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   17 |   int m = l + r >> 1;
      |           ~~^~~
game.cpp: In function 'void run(int, int, int, int, bool, std::vector<int>&, int)':
game.cpp:69:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   69 |   int m = l + r >> 1;
      |           ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 37864 KB Output is correct
2 Correct 19 ms 37792 KB Output is correct
3 Correct 18 ms 37860 KB Output is correct
4 Correct 18 ms 37808 KB Output is correct
5 Correct 18 ms 37912 KB Output is correct
6 Correct 18 ms 37840 KB Output is correct
7 Correct 17 ms 37948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 37864 KB Output is correct
2 Correct 19 ms 37792 KB Output is correct
3 Correct 18 ms 37860 KB Output is correct
4 Correct 18 ms 37808 KB Output is correct
5 Correct 18 ms 37912 KB Output is correct
6 Correct 18 ms 37840 KB Output is correct
7 Correct 17 ms 37948 KB Output is correct
8 Correct 17 ms 37772 KB Output is correct
9 Correct 17 ms 37840 KB Output is correct
10 Correct 23 ms 37840 KB Output is correct
11 Correct 19 ms 37848 KB Output is correct
12 Correct 24 ms 37796 KB Output is correct
13 Incorrect 20 ms 37836 KB Wrong Answer[1]
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 37864 KB Output is correct
2 Correct 19 ms 37792 KB Output is correct
3 Correct 18 ms 37860 KB Output is correct
4 Correct 18 ms 37808 KB Output is correct
5 Correct 18 ms 37912 KB Output is correct
6 Correct 18 ms 37840 KB Output is correct
7 Correct 17 ms 37948 KB Output is correct
8 Correct 17 ms 37772 KB Output is correct
9 Correct 17 ms 37840 KB Output is correct
10 Correct 23 ms 37840 KB Output is correct
11 Correct 19 ms 37848 KB Output is correct
12 Correct 24 ms 37796 KB Output is correct
13 Incorrect 20 ms 37836 KB Wrong Answer[1]
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 37864 KB Output is correct
2 Correct 19 ms 37792 KB Output is correct
3 Correct 18 ms 37860 KB Output is correct
4 Correct 18 ms 37808 KB Output is correct
5 Correct 18 ms 37912 KB Output is correct
6 Correct 18 ms 37840 KB Output is correct
7 Correct 17 ms 37948 KB Output is correct
8 Correct 17 ms 37772 KB Output is correct
9 Correct 17 ms 37840 KB Output is correct
10 Correct 23 ms 37840 KB Output is correct
11 Correct 19 ms 37848 KB Output is correct
12 Correct 24 ms 37796 KB Output is correct
13 Incorrect 20 ms 37836 KB Wrong Answer[1]
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 37864 KB Output is correct
2 Correct 19 ms 37792 KB Output is correct
3 Correct 18 ms 37860 KB Output is correct
4 Correct 18 ms 37808 KB Output is correct
5 Correct 18 ms 37912 KB Output is correct
6 Correct 18 ms 37840 KB Output is correct
7 Correct 17 ms 37948 KB Output is correct
8 Correct 17 ms 37772 KB Output is correct
9 Correct 17 ms 37840 KB Output is correct
10 Correct 23 ms 37840 KB Output is correct
11 Correct 19 ms 37848 KB Output is correct
12 Correct 24 ms 37796 KB Output is correct
13 Incorrect 20 ms 37836 KB Wrong Answer[1]
14 Halted 0 ms 0 KB -