답안 #774279

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
774279 2023-07-05T13:36:14 Z LittleCube 게임 (APIO22_game) C++17
100 / 100
3760 ms 233824 KB
#pragma GCC optimize("Ofast,unroll-loops")
#include "game.h"
#ifndef EVAL
#include "game_grader.cpp"
#endif
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
using namespace std;

namespace
{
  const int P = 12;
  int n, k, from[300000][7], to[300000][7], where[300000][7];
  vector<int> Ef[300000][7], Et[300000][7];
  void update_from(int u, int layer, vector<int> &same)
  {
    if (from[u][layer] == to[u][layer])
      same.emplace_back(u);
    for (auto v : Ef[u][layer])
      if (from[u][layer] > from[v][layer])
      {
        from[v][layer] = from[u][layer];
        update_from(v, layer, same);
      }
  }
  void update_to(int u, int layer, vector<int> &same)
  {
    if (from[u][layer] == to[u][layer])
      same.emplace_back(u);
    for (auto v : Et[u][layer])
      if (to[u][layer] < to[v][layer])
      {
        to[v][layer] = to[u][layer];
        update_to(v, layer, same);
      }
  }

  void build(int i = 1, int L = 0, int R = k - 1, int l = 0)
  {
    for (int j = L; j <= R; j++)
      where[j][l] = i;
    if (L != R)
    {
      int range = (R - L + P) / P;
      for (int j = 1; j <= P; j++)
      {
        int ml = L + range * (j - 1), mr = min(R, L + range * j - 1);
        for (int p = ml; p <= mr; p++)
          from[p][l] = to[p][l] = j;
        if (ml <= mr)
          build(i * P + (j - 1), ml, mr, l + 1);
      }
    }
    else
      from[L][l] = 2, to[L][l] = 1;
  }

  int add_edge(int, int, int, int);

  int add_node(int u, int i, int l)
  {
    if (where[u][l])
      return 0;
    where[u][l] = i;
    from[u][l] = 0, to[u][l] = P + 1;
    bool flag = 0;
    for (auto v : Et[u][l - 1])
      if (where[u][l] == where[v][l])
        flag |= add_edge(v, u, i, l);
    for (auto v : Ef[u][l - 1])
      if (where[u][l] == where[v][l])
        flag |= add_edge(u, v, i, l);

    return flag | (from[u][l] > to[u][l]);
  }

  int add_edge(int u, int v, int i = 1, int l = 0)
  {
    Ef[u][l].emplace_back(v);
    Et[v][l].emplace_back(u);
    vector<int> s;
    bool flag = 0;
    if (v >= k && from[v][l] < from[u][l])
    {
      from[v][l] = from[u][l];
      update_from(v, l, s);
      flag |= (from[v][l] > to[v][l]);
    }
    if (u >= k && to[u][l] > to[v][l])
    {
      to[u][l] = to[v][l];
      update_to(u, l, s);
      flag |= (from[u][l] > to[u][l]);
    }
    if (where[u][l + 1] == where[v][l + 1] && where[u][l + 1] > 0)
      flag |= add_edge(u, v, where[u][l + 1], l + 1);
    for (int w : s)
      flag |= add_node(w, i * P + (from[w][l] - 1), l + 1);
    return flag;
  }
}

void init(int n, int k)
{
  ::n = n, ::k = k;
  build();
  for (int i = k; i < n; i++)
  {
    from[i][0] = 0, to[i][0] = P + 1;
    where[i][0] = 1;
  }
}

int add_teleporter(int u, int v)
{
  if (u < k && v < k)
  {
    if (v <= u)
      return 1;
    return 0;
  }
  bool ans = add_edge(u, v);
  // cout << u << ' ' << v << '\n';
  // for (int p = 0; p < 5; p++)
  //   for (int i = 0; i < n; i++)
  //     cout << from[i][p] << ' ' << to[i][p] << ' ' << " \n"[i == n - 1];

  // for (int p = 0; p < 5; p++)
  //   for (int i = 0; i < n; i++)
  //     cout << where[i][p] << " \n"[i == n - 1];
  // cout << '\n';
  return ans;
}

Compilation message

game.cpp: In function 'void init(int, int)':
game.cpp:43:17: warning: array subscript 7 is above array bounds of 'int [7]' [-Warray-bounds]
   43 |       where[j][l] = i;
      |       ~~~~~~~~~~^
game.cpp:57:16: warning: array subscript 7 is above array bounds of 'int [7]' [-Warray-bounds]
   57 |       from[L][l] = 2, to[L][l] = 1;
      |       ~~~~~~~~~^
game.cpp:57:30: warning: array subscript 7 is above array bounds of 'int [7]' [-Warray-bounds]
   57 |       from[L][l] = 2, to[L][l] = 1;
      |                       ~~~~~~~^
game.cpp:51:31: warning: array subscript 7 is above array bounds of 'int [7]' [-Warray-bounds]
   51 |           from[p][l] = to[p][l] = j;
      |                        ~~~~~~~^
game.cpp:51:20: warning: array subscript 7 is above array bounds of 'int [7]' [-Warray-bounds]
   51 |           from[p][l] = to[p][l] = j;
      |           ~~~~~~~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 98896 KB Output is correct
2 Correct 49 ms 98892 KB Output is correct
3 Correct 49 ms 98912 KB Output is correct
4 Correct 49 ms 98896 KB Output is correct
5 Correct 49 ms 98832 KB Output is correct
6 Correct 50 ms 98932 KB Output is correct
7 Correct 50 ms 98876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 98896 KB Output is correct
2 Correct 49 ms 98892 KB Output is correct
3 Correct 49 ms 98912 KB Output is correct
4 Correct 49 ms 98896 KB Output is correct
5 Correct 49 ms 98832 KB Output is correct
6 Correct 50 ms 98932 KB Output is correct
7 Correct 50 ms 98876 KB Output is correct
8 Correct 50 ms 98876 KB Output is correct
9 Correct 50 ms 98816 KB Output is correct
10 Correct 51 ms 98848 KB Output is correct
11 Correct 51 ms 98928 KB Output is correct
12 Correct 49 ms 98912 KB Output is correct
13 Correct 51 ms 98836 KB Output is correct
14 Correct 50 ms 98912 KB Output is correct
15 Correct 50 ms 98888 KB Output is correct
16 Correct 49 ms 98912 KB Output is correct
17 Correct 49 ms 98872 KB Output is correct
18 Correct 50 ms 98964 KB Output is correct
19 Correct 50 ms 98884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 98896 KB Output is correct
2 Correct 49 ms 98892 KB Output is correct
3 Correct 49 ms 98912 KB Output is correct
4 Correct 49 ms 98896 KB Output is correct
5 Correct 49 ms 98832 KB Output is correct
6 Correct 50 ms 98932 KB Output is correct
7 Correct 50 ms 98876 KB Output is correct
8 Correct 50 ms 98876 KB Output is correct
9 Correct 50 ms 98816 KB Output is correct
10 Correct 51 ms 98848 KB Output is correct
11 Correct 51 ms 98928 KB Output is correct
12 Correct 49 ms 98912 KB Output is correct
13 Correct 51 ms 98836 KB Output is correct
14 Correct 50 ms 98912 KB Output is correct
15 Correct 50 ms 98888 KB Output is correct
16 Correct 49 ms 98912 KB Output is correct
17 Correct 49 ms 98872 KB Output is correct
18 Correct 50 ms 98964 KB Output is correct
19 Correct 50 ms 98884 KB Output is correct
20 Correct 50 ms 99028 KB Output is correct
21 Correct 50 ms 98984 KB Output is correct
22 Correct 51 ms 99092 KB Output is correct
23 Correct 50 ms 99088 KB Output is correct
24 Correct 52 ms 99144 KB Output is correct
25 Correct 52 ms 99152 KB Output is correct
26 Correct 52 ms 99000 KB Output is correct
27 Correct 52 ms 99104 KB Output is correct
28 Correct 51 ms 99056 KB Output is correct
29 Correct 51 ms 99148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 98896 KB Output is correct
2 Correct 49 ms 98892 KB Output is correct
3 Correct 49 ms 98912 KB Output is correct
4 Correct 49 ms 98896 KB Output is correct
5 Correct 49 ms 98832 KB Output is correct
6 Correct 50 ms 98932 KB Output is correct
7 Correct 50 ms 98876 KB Output is correct
8 Correct 50 ms 98876 KB Output is correct
9 Correct 50 ms 98816 KB Output is correct
10 Correct 51 ms 98848 KB Output is correct
11 Correct 51 ms 98928 KB Output is correct
12 Correct 49 ms 98912 KB Output is correct
13 Correct 51 ms 98836 KB Output is correct
14 Correct 50 ms 98912 KB Output is correct
15 Correct 50 ms 98888 KB Output is correct
16 Correct 49 ms 98912 KB Output is correct
17 Correct 49 ms 98872 KB Output is correct
18 Correct 50 ms 98964 KB Output is correct
19 Correct 50 ms 98884 KB Output is correct
20 Correct 50 ms 99028 KB Output is correct
21 Correct 50 ms 98984 KB Output is correct
22 Correct 51 ms 99092 KB Output is correct
23 Correct 50 ms 99088 KB Output is correct
24 Correct 52 ms 99144 KB Output is correct
25 Correct 52 ms 99152 KB Output is correct
26 Correct 52 ms 99000 KB Output is correct
27 Correct 52 ms 99104 KB Output is correct
28 Correct 51 ms 99056 KB Output is correct
29 Correct 51 ms 99148 KB Output is correct
30 Correct 68 ms 102528 KB Output is correct
31 Correct 57 ms 101784 KB Output is correct
32 Correct 79 ms 104572 KB Output is correct
33 Correct 72 ms 103196 KB Output is correct
34 Correct 149 ms 111440 KB Output is correct
35 Correct 97 ms 106040 KB Output is correct
36 Correct 96 ms 103804 KB Output is correct
37 Correct 101 ms 106824 KB Output is correct
38 Correct 89 ms 103700 KB Output is correct
39 Correct 95 ms 104240 KB Output is correct
40 Correct 134 ms 110888 KB Output is correct
41 Correct 98 ms 104780 KB Output is correct
42 Correct 85 ms 104136 KB Output is correct
43 Correct 143 ms 109528 KB Output is correct
44 Correct 123 ms 109128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 98896 KB Output is correct
2 Correct 49 ms 98892 KB Output is correct
3 Correct 49 ms 98912 KB Output is correct
4 Correct 49 ms 98896 KB Output is correct
5 Correct 49 ms 98832 KB Output is correct
6 Correct 50 ms 98932 KB Output is correct
7 Correct 50 ms 98876 KB Output is correct
8 Correct 50 ms 98876 KB Output is correct
9 Correct 50 ms 98816 KB Output is correct
10 Correct 51 ms 98848 KB Output is correct
11 Correct 51 ms 98928 KB Output is correct
12 Correct 49 ms 98912 KB Output is correct
13 Correct 51 ms 98836 KB Output is correct
14 Correct 50 ms 98912 KB Output is correct
15 Correct 50 ms 98888 KB Output is correct
16 Correct 49 ms 98912 KB Output is correct
17 Correct 49 ms 98872 KB Output is correct
18 Correct 50 ms 98964 KB Output is correct
19 Correct 50 ms 98884 KB Output is correct
20 Correct 50 ms 99028 KB Output is correct
21 Correct 50 ms 98984 KB Output is correct
22 Correct 51 ms 99092 KB Output is correct
23 Correct 50 ms 99088 KB Output is correct
24 Correct 52 ms 99144 KB Output is correct
25 Correct 52 ms 99152 KB Output is correct
26 Correct 52 ms 99000 KB Output is correct
27 Correct 52 ms 99104 KB Output is correct
28 Correct 51 ms 99056 KB Output is correct
29 Correct 51 ms 99148 KB Output is correct
30 Correct 68 ms 102528 KB Output is correct
31 Correct 57 ms 101784 KB Output is correct
32 Correct 79 ms 104572 KB Output is correct
33 Correct 72 ms 103196 KB Output is correct
34 Correct 149 ms 111440 KB Output is correct
35 Correct 97 ms 106040 KB Output is correct
36 Correct 96 ms 103804 KB Output is correct
37 Correct 101 ms 106824 KB Output is correct
38 Correct 89 ms 103700 KB Output is correct
39 Correct 95 ms 104240 KB Output is correct
40 Correct 134 ms 110888 KB Output is correct
41 Correct 98 ms 104780 KB Output is correct
42 Correct 85 ms 104136 KB Output is correct
43 Correct 143 ms 109528 KB Output is correct
44 Correct 123 ms 109128 KB Output is correct
45 Correct 319 ms 134868 KB Output is correct
46 Correct 65 ms 123976 KB Output is correct
47 Correct 70 ms 123888 KB Output is correct
48 Correct 520 ms 156628 KB Output is correct
49 Correct 381 ms 142340 KB Output is correct
50 Correct 2609 ms 200272 KB Output is correct
51 Correct 1318 ms 173220 KB Output is correct
52 Correct 824 ms 144792 KB Output is correct
53 Correct 1372 ms 177012 KB Output is correct
54 Correct 1365 ms 185628 KB Output is correct
55 Correct 2768 ms 179660 KB Output is correct
56 Correct 3500 ms 196676 KB Output is correct
57 Correct 676 ms 153484 KB Output is correct
58 Correct 742 ms 153148 KB Output is correct
59 Correct 705 ms 154564 KB Output is correct
60 Correct 1330 ms 154728 KB Output is correct
61 Correct 1499 ms 163056 KB Output is correct
62 Correct 967 ms 168188 KB Output is correct
63 Correct 904 ms 164696 KB Output is correct
64 Correct 3026 ms 233824 KB Output is correct
65 Correct 803 ms 153732 KB Output is correct
66 Correct 679 ms 149760 KB Output is correct
67 Correct 1452 ms 164528 KB Output is correct
68 Correct 283 ms 133244 KB Output is correct
69 Correct 132 ms 127048 KB Output is correct
70 Correct 1214 ms 161344 KB Output is correct
71 Correct 409 ms 135228 KB Output is correct
72 Correct 323 ms 131072 KB Output is correct
73 Correct 991 ms 153248 KB Output is correct
74 Correct 3760 ms 181944 KB Output is correct
75 Correct 2311 ms 223424 KB Output is correct
76 Correct 2585 ms 211740 KB Output is correct