답안 #578333

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
578333 2022-06-16T11:43:11 Z nonsensenonsense1 게임 (APIO22_game) C++17
100 / 100
2483 ms 86824 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);
  for (int i = 0; i < n; ++i)
    ind[0][i] = 0;
}

vector<int> ladd, radd;
void addright(int v, int lvl) {
  if (right[lvl][v])
    return;
  radd.push_back(v);
  ind[lvl + 1][v] = ind[lvl][v] * 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);
}

void addleft(int v, int lvl) {
  if (left[lvl][v])
    return;
  ladd.push_back(v);
  ind[lvl + 1][v] = ind[lvl][v] * 2 + 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);
}

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);
    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);
  }
  if (edg) {
    if (right[lvl][u])
      addright(v, lvl);
    if (left[lvl][v])
      addleft(u, lvl);
  }
  vector<int> ladd1 = ladd, radd1 = radd;
  if (m + 1 < r) {
    run(m + 1, r, u, v,
        u != m && v != m && edg && right[lvl][u] && right[lvl][v], radd1,
        lvl + 1);
  }
  if (l < m) {
    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;
  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:70:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   70 |   int m = l + r >> 1;
      |           ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 37840 KB Output is correct
2 Correct 23 ms 37792 KB Output is correct
3 Correct 18 ms 37832 KB Output is correct
4 Correct 17 ms 37840 KB Output is correct
5 Correct 17 ms 37948 KB Output is correct
6 Correct 17 ms 37844 KB Output is correct
7 Correct 18 ms 37864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 37840 KB Output is correct
2 Correct 23 ms 37792 KB Output is correct
3 Correct 18 ms 37832 KB Output is correct
4 Correct 17 ms 37840 KB Output is correct
5 Correct 17 ms 37948 KB Output is correct
6 Correct 17 ms 37844 KB Output is correct
7 Correct 18 ms 37864 KB Output is correct
8 Correct 19 ms 37840 KB Output is correct
9 Correct 17 ms 37840 KB Output is correct
10 Correct 17 ms 37856 KB Output is correct
11 Correct 22 ms 37828 KB Output is correct
12 Correct 20 ms 37832 KB Output is correct
13 Correct 19 ms 37840 KB Output is correct
14 Correct 19 ms 37840 KB Output is correct
15 Correct 20 ms 37840 KB Output is correct
16 Correct 18 ms 37916 KB Output is correct
17 Correct 18 ms 37840 KB Output is correct
18 Correct 17 ms 37840 KB Output is correct
19 Correct 18 ms 37840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 37840 KB Output is correct
2 Correct 23 ms 37792 KB Output is correct
3 Correct 18 ms 37832 KB Output is correct
4 Correct 17 ms 37840 KB Output is correct
5 Correct 17 ms 37948 KB Output is correct
6 Correct 17 ms 37844 KB Output is correct
7 Correct 18 ms 37864 KB Output is correct
8 Correct 19 ms 37840 KB Output is correct
9 Correct 17 ms 37840 KB Output is correct
10 Correct 17 ms 37856 KB Output is correct
11 Correct 22 ms 37828 KB Output is correct
12 Correct 20 ms 37832 KB Output is correct
13 Correct 19 ms 37840 KB Output is correct
14 Correct 19 ms 37840 KB Output is correct
15 Correct 20 ms 37840 KB Output is correct
16 Correct 18 ms 37916 KB Output is correct
17 Correct 18 ms 37840 KB Output is correct
18 Correct 17 ms 37840 KB Output is correct
19 Correct 18 ms 37840 KB Output is correct
20 Correct 17 ms 37856 KB Output is correct
21 Correct 17 ms 37840 KB Output is correct
22 Correct 18 ms 37968 KB Output is correct
23 Correct 21 ms 37864 KB Output is correct
24 Correct 19 ms 37968 KB Output is correct
25 Correct 20 ms 38004 KB Output is correct
26 Correct 21 ms 37968 KB Output is correct
27 Correct 20 ms 37988 KB Output is correct
28 Correct 22 ms 37976 KB Output is correct
29 Correct 21 ms 38036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 37840 KB Output is correct
2 Correct 23 ms 37792 KB Output is correct
3 Correct 18 ms 37832 KB Output is correct
4 Correct 17 ms 37840 KB Output is correct
5 Correct 17 ms 37948 KB Output is correct
6 Correct 17 ms 37844 KB Output is correct
7 Correct 18 ms 37864 KB Output is correct
8 Correct 19 ms 37840 KB Output is correct
9 Correct 17 ms 37840 KB Output is correct
10 Correct 17 ms 37856 KB Output is correct
11 Correct 22 ms 37828 KB Output is correct
12 Correct 20 ms 37832 KB Output is correct
13 Correct 19 ms 37840 KB Output is correct
14 Correct 19 ms 37840 KB Output is correct
15 Correct 20 ms 37840 KB Output is correct
16 Correct 18 ms 37916 KB Output is correct
17 Correct 18 ms 37840 KB Output is correct
18 Correct 17 ms 37840 KB Output is correct
19 Correct 18 ms 37840 KB Output is correct
20 Correct 17 ms 37856 KB Output is correct
21 Correct 17 ms 37840 KB Output is correct
22 Correct 18 ms 37968 KB Output is correct
23 Correct 21 ms 37864 KB Output is correct
24 Correct 19 ms 37968 KB Output is correct
25 Correct 20 ms 38004 KB Output is correct
26 Correct 21 ms 37968 KB Output is correct
27 Correct 20 ms 37988 KB Output is correct
28 Correct 22 ms 37976 KB Output is correct
29 Correct 21 ms 38036 KB Output is correct
30 Correct 39 ms 39376 KB Output is correct
31 Correct 26 ms 38568 KB Output is correct
32 Correct 65 ms 41548 KB Output is correct
33 Correct 36 ms 39948 KB Output is correct
34 Correct 58 ms 42652 KB Output is correct
35 Correct 68 ms 41516 KB Output is correct
36 Correct 61 ms 40288 KB Output is correct
37 Correct 107 ms 41028 KB Output is correct
38 Correct 79 ms 40244 KB Output is correct
39 Correct 58 ms 40228 KB Output is correct
40 Correct 84 ms 43404 KB Output is correct
41 Correct 72 ms 40924 KB Output is correct
42 Correct 57 ms 40520 KB Output is correct
43 Correct 138 ms 41824 KB Output is correct
44 Correct 65 ms 41448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 37840 KB Output is correct
2 Correct 23 ms 37792 KB Output is correct
3 Correct 18 ms 37832 KB Output is correct
4 Correct 17 ms 37840 KB Output is correct
5 Correct 17 ms 37948 KB Output is correct
6 Correct 17 ms 37844 KB Output is correct
7 Correct 18 ms 37864 KB Output is correct
8 Correct 19 ms 37840 KB Output is correct
9 Correct 17 ms 37840 KB Output is correct
10 Correct 17 ms 37856 KB Output is correct
11 Correct 22 ms 37828 KB Output is correct
12 Correct 20 ms 37832 KB Output is correct
13 Correct 19 ms 37840 KB Output is correct
14 Correct 19 ms 37840 KB Output is correct
15 Correct 20 ms 37840 KB Output is correct
16 Correct 18 ms 37916 KB Output is correct
17 Correct 18 ms 37840 KB Output is correct
18 Correct 17 ms 37840 KB Output is correct
19 Correct 18 ms 37840 KB Output is correct
20 Correct 17 ms 37856 KB Output is correct
21 Correct 17 ms 37840 KB Output is correct
22 Correct 18 ms 37968 KB Output is correct
23 Correct 21 ms 37864 KB Output is correct
24 Correct 19 ms 37968 KB Output is correct
25 Correct 20 ms 38004 KB Output is correct
26 Correct 21 ms 37968 KB Output is correct
27 Correct 20 ms 37988 KB Output is correct
28 Correct 22 ms 37976 KB Output is correct
29 Correct 21 ms 38036 KB Output is correct
30 Correct 39 ms 39376 KB Output is correct
31 Correct 26 ms 38568 KB Output is correct
32 Correct 65 ms 41548 KB Output is correct
33 Correct 36 ms 39948 KB Output is correct
34 Correct 58 ms 42652 KB Output is correct
35 Correct 68 ms 41516 KB Output is correct
36 Correct 61 ms 40288 KB Output is correct
37 Correct 107 ms 41028 KB Output is correct
38 Correct 79 ms 40244 KB Output is correct
39 Correct 58 ms 40228 KB Output is correct
40 Correct 84 ms 43404 KB Output is correct
41 Correct 72 ms 40924 KB Output is correct
42 Correct 57 ms 40520 KB Output is correct
43 Correct 138 ms 41824 KB Output is correct
44 Correct 65 ms 41448 KB Output is correct
45 Correct 287 ms 51792 KB Output is correct
46 Correct 24 ms 38492 KB Output is correct
47 Correct 22 ms 38592 KB Output is correct
48 Correct 778 ms 74412 KB Output is correct
49 Correct 346 ms 60156 KB Output is correct
50 Correct 986 ms 74012 KB Output is correct
51 Correct 1464 ms 73664 KB Output is correct
52 Correct 907 ms 60484 KB Output is correct
53 Correct 1475 ms 66928 KB Output is correct
54 Correct 1338 ms 64376 KB Output is correct
55 Correct 1504 ms 65612 KB Output is correct
56 Correct 2483 ms 74468 KB Output is correct
57 Correct 737 ms 60844 KB Output is correct
58 Correct 830 ms 60288 KB Output is correct
59 Correct 863 ms 60924 KB Output is correct
60 Correct 817 ms 63312 KB Output is correct
61 Correct 1020 ms 61320 KB Output is correct
62 Correct 601 ms 65012 KB Output is correct
63 Correct 518 ms 61956 KB Output is correct
64 Correct 1691 ms 86824 KB Output is correct
65 Correct 746 ms 65392 KB Output is correct
66 Correct 627 ms 61684 KB Output is correct
67 Correct 1252 ms 70304 KB Output is correct
68 Correct 236 ms 53664 KB Output is correct
69 Correct 69 ms 48236 KB Output is correct
70 Correct 1256 ms 69372 KB Output is correct
71 Correct 476 ms 58700 KB Output is correct
72 Correct 318 ms 54504 KB Output is correct
73 Correct 1002 ms 66756 KB Output is correct
74 Correct 2123 ms 69192 KB Output is correct
75 Correct 1954 ms 78480 KB Output is correct
76 Correct 1369 ms 83732 KB Output is correct