답안 #773530

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
773530 2023-07-05T06:31:35 Z LittleCube 게임 (APIO22_game) C++17
60 / 100
4000 ms 200176 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
{
  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 + 16) / 16;
      for (int j = 1; j <= 16; 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 << 4 | (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] = 17;
    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);
    from[v][l] = max(from[v][l], from[u][l]);
    to[u][l] = min(to[u][l], to[v][l]);
    vector<int> s;
    bool flag = 0;
    if (v >= k)
    {
      update_from(v, l, s);
      flag |= (from[v][l] > to[v][l]);
    }
    if (u >= k)
    {
      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 << 4 | (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] = 17;
    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:42:17: warning: array subscript 7 is above array bounds of 'int [7]' [-Warray-bounds]
   42 |       where[j][l] = i;
      |       ~~~~~~~~~~^
game.cpp:56:16: warning: array subscript 7 is above array bounds of 'int [7]' [-Warray-bounds]
   56 |       from[L][l] = 2, to[L][l] = 1;
      |       ~~~~~~~~~^
game.cpp:56:30: warning: array subscript 7 is above array bounds of 'int [7]' [-Warray-bounds]
   56 |       from[L][l] = 2, to[L][l] = 1;
      |                       ~~~~~~~^
game.cpp:50:31: warning: array subscript 7 is above array bounds of 'int [7]' [-Warray-bounds]
   50 |           from[p][l] = to[p][l] = j;
      |                        ~~~~~~~^
game.cpp:50:20: warning: array subscript 7 is above array bounds of 'int [7]' [-Warray-bounds]
   50 |           from[p][l] = to[p][l] = j;
      |           ~~~~~~~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 98888 KB Output is correct
2 Correct 51 ms 98808 KB Output is correct
3 Correct 49 ms 98896 KB Output is correct
4 Correct 50 ms 98860 KB Output is correct
5 Correct 50 ms 98888 KB Output is correct
6 Correct 58 ms 98856 KB Output is correct
7 Correct 60 ms 98852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 98888 KB Output is correct
2 Correct 51 ms 98808 KB Output is correct
3 Correct 49 ms 98896 KB Output is correct
4 Correct 50 ms 98860 KB Output is correct
5 Correct 50 ms 98888 KB Output is correct
6 Correct 58 ms 98856 KB Output is correct
7 Correct 60 ms 98852 KB Output is correct
8 Correct 52 ms 98892 KB Output is correct
9 Correct 52 ms 98868 KB Output is correct
10 Correct 48 ms 98888 KB Output is correct
11 Correct 55 ms 98904 KB Output is correct
12 Correct 51 ms 98812 KB Output is correct
13 Correct 65 ms 98908 KB Output is correct
14 Correct 50 ms 98872 KB Output is correct
15 Correct 50 ms 98868 KB Output is correct
16 Correct 56 ms 98908 KB Output is correct
17 Correct 50 ms 98956 KB Output is correct
18 Correct 48 ms 98896 KB Output is correct
19 Correct 50 ms 98860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 98888 KB Output is correct
2 Correct 51 ms 98808 KB Output is correct
3 Correct 49 ms 98896 KB Output is correct
4 Correct 50 ms 98860 KB Output is correct
5 Correct 50 ms 98888 KB Output is correct
6 Correct 58 ms 98856 KB Output is correct
7 Correct 60 ms 98852 KB Output is correct
8 Correct 52 ms 98892 KB Output is correct
9 Correct 52 ms 98868 KB Output is correct
10 Correct 48 ms 98888 KB Output is correct
11 Correct 55 ms 98904 KB Output is correct
12 Correct 51 ms 98812 KB Output is correct
13 Correct 65 ms 98908 KB Output is correct
14 Correct 50 ms 98872 KB Output is correct
15 Correct 50 ms 98868 KB Output is correct
16 Correct 56 ms 98908 KB Output is correct
17 Correct 50 ms 98956 KB Output is correct
18 Correct 48 ms 98896 KB Output is correct
19 Correct 50 ms 98860 KB Output is correct
20 Correct 49 ms 99024 KB Output is correct
21 Correct 64 ms 98932 KB Output is correct
22 Correct 53 ms 99100 KB Output is correct
23 Correct 56 ms 99004 KB Output is correct
24 Correct 53 ms 99140 KB Output is correct
25 Correct 54 ms 99060 KB Output is correct
26 Correct 55 ms 99136 KB Output is correct
27 Correct 54 ms 99152 KB Output is correct
28 Correct 54 ms 99084 KB Output is correct
29 Correct 54 ms 99060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 98888 KB Output is correct
2 Correct 51 ms 98808 KB Output is correct
3 Correct 49 ms 98896 KB Output is correct
4 Correct 50 ms 98860 KB Output is correct
5 Correct 50 ms 98888 KB Output is correct
6 Correct 58 ms 98856 KB Output is correct
7 Correct 60 ms 98852 KB Output is correct
8 Correct 52 ms 98892 KB Output is correct
9 Correct 52 ms 98868 KB Output is correct
10 Correct 48 ms 98888 KB Output is correct
11 Correct 55 ms 98904 KB Output is correct
12 Correct 51 ms 98812 KB Output is correct
13 Correct 65 ms 98908 KB Output is correct
14 Correct 50 ms 98872 KB Output is correct
15 Correct 50 ms 98868 KB Output is correct
16 Correct 56 ms 98908 KB Output is correct
17 Correct 50 ms 98956 KB Output is correct
18 Correct 48 ms 98896 KB Output is correct
19 Correct 50 ms 98860 KB Output is correct
20 Correct 49 ms 99024 KB Output is correct
21 Correct 64 ms 98932 KB Output is correct
22 Correct 53 ms 99100 KB Output is correct
23 Correct 56 ms 99004 KB Output is correct
24 Correct 53 ms 99140 KB Output is correct
25 Correct 54 ms 99060 KB Output is correct
26 Correct 55 ms 99136 KB Output is correct
27 Correct 54 ms 99152 KB Output is correct
28 Correct 54 ms 99084 KB Output is correct
29 Correct 54 ms 99060 KB Output is correct
30 Correct 72 ms 102560 KB Output is correct
31 Correct 60 ms 101736 KB Output is correct
32 Correct 85 ms 104576 KB Output is correct
33 Correct 82 ms 103304 KB Output is correct
34 Correct 178 ms 111440 KB Output is correct
35 Correct 105 ms 106020 KB Output is correct
36 Correct 124 ms 104672 KB Output is correct
37 Correct 107 ms 106788 KB Output is correct
38 Correct 95 ms 103468 KB Output is correct
39 Correct 93 ms 104056 KB Output is correct
40 Correct 147 ms 110856 KB Output is correct
41 Correct 97 ms 104780 KB Output is correct
42 Correct 100 ms 103856 KB Output is correct
43 Correct 141 ms 109384 KB Output is correct
44 Correct 149 ms 108856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 98888 KB Output is correct
2 Correct 51 ms 98808 KB Output is correct
3 Correct 49 ms 98896 KB Output is correct
4 Correct 50 ms 98860 KB Output is correct
5 Correct 50 ms 98888 KB Output is correct
6 Correct 58 ms 98856 KB Output is correct
7 Correct 60 ms 98852 KB Output is correct
8 Correct 52 ms 98892 KB Output is correct
9 Correct 52 ms 98868 KB Output is correct
10 Correct 48 ms 98888 KB Output is correct
11 Correct 55 ms 98904 KB Output is correct
12 Correct 51 ms 98812 KB Output is correct
13 Correct 65 ms 98908 KB Output is correct
14 Correct 50 ms 98872 KB Output is correct
15 Correct 50 ms 98868 KB Output is correct
16 Correct 56 ms 98908 KB Output is correct
17 Correct 50 ms 98956 KB Output is correct
18 Correct 48 ms 98896 KB Output is correct
19 Correct 50 ms 98860 KB Output is correct
20 Correct 49 ms 99024 KB Output is correct
21 Correct 64 ms 98932 KB Output is correct
22 Correct 53 ms 99100 KB Output is correct
23 Correct 56 ms 99004 KB Output is correct
24 Correct 53 ms 99140 KB Output is correct
25 Correct 54 ms 99060 KB Output is correct
26 Correct 55 ms 99136 KB Output is correct
27 Correct 54 ms 99152 KB Output is correct
28 Correct 54 ms 99084 KB Output is correct
29 Correct 54 ms 99060 KB Output is correct
30 Correct 72 ms 102560 KB Output is correct
31 Correct 60 ms 101736 KB Output is correct
32 Correct 85 ms 104576 KB Output is correct
33 Correct 82 ms 103304 KB Output is correct
34 Correct 178 ms 111440 KB Output is correct
35 Correct 105 ms 106020 KB Output is correct
36 Correct 124 ms 104672 KB Output is correct
37 Correct 107 ms 106788 KB Output is correct
38 Correct 95 ms 103468 KB Output is correct
39 Correct 93 ms 104056 KB Output is correct
40 Correct 147 ms 110856 KB Output is correct
41 Correct 97 ms 104780 KB Output is correct
42 Correct 100 ms 103856 KB Output is correct
43 Correct 141 ms 109384 KB Output is correct
44 Correct 149 ms 108856 KB Output is correct
45 Correct 381 ms 134940 KB Output is correct
46 Correct 67 ms 123976 KB Output is correct
47 Correct 67 ms 123848 KB Output is correct
48 Correct 540 ms 156572 KB Output is correct
49 Correct 471 ms 142296 KB Output is correct
50 Correct 2821 ms 200176 KB Output is correct
51 Correct 1453 ms 172820 KB Output is correct
52 Correct 1046 ms 154656 KB Output is correct
53 Correct 1482 ms 176948 KB Output is correct
54 Correct 1593 ms 183928 KB Output is correct
55 Correct 3348 ms 175192 KB Output is correct
56 Execution timed out 4083 ms 195008 KB Time limit exceeded
57 Halted 0 ms 0 KB -