QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#646565#408. Dungeon 2maspy0 23ms4592kbC++143.8kb2024-10-17 01:06:092024-10-17 01:06:09

Judging History

你现在查看的是最新测评结果

  • [2024-10-17 01:06:09]
  • 评测
  • 测评结果:0
  • 用时:23ms
  • 内存:4592kb
  • [2024-10-17 01:06:09]
  • 提交

answer

#include "dungeon2.h"
#include "bits/stdc++.h"

/*
逆辺は見える!
最初に dfs, 2色あれば初到時刻でラベル付けできる
ラベル付きグラフとしてよい

2M 回で分かる
- 頂点ラベル
- DFS 木の辺

3色目をつかえば、DFS木の頂点 mod 2 とかも分かるかも

あれ、できてる?
dfs しながら、3 色で塗る (3-adic の k-th bit)
全部で 6 DFS
12回

うそ!
どこからの逆辺かはわからないので初回+2
これで14回、いいね

初回
未到達 1
先祖 2
dfs 済 3
*/

using namespace std;
template <typename T>
using vc = vector<T>;
template <typename T>
using vvc = vc<vc<T>>;

enum etype { TREE_UP, TREE_DOWN, BACK_UP, BACK_DOWN };

struct Data {
  etype tp;
  int to = 0;
};
vvc<Data> dat;

int color_memo;

void change_color(int i) { color_memo = i; }
void GO(int i) {
  Move(1 + i, color_memo);
  color_memo = Color();
}
int LAST() { return LastRoad() - 1; }

void Inspect(int R) {
  int n = 0;
  auto new_v = [&](int p) -> int {
    int d = NumberOfRoads();
    int k = LAST();
    dat.resize(n + 1);
    dat[n].resize(d);
    if (k != -1) {
      dat[n][k].tp = TREE_UP;
      dat[n][k].to = p;
    }
    return n++;
  };

  int v = new_v(-1);
  {
    auto dfs = [&](auto& dfs, int v) -> void {
      int d = dat[v].size();
      int last = LAST();
      change_color(2);
      for (int i = 0; i < d; ++i) {
        if (last == i) {
          assert(dat[v][i].tp == TREE_UP);
          continue;
        }
        GO(i);
        if (Color() == 2) {
          // 後退辺でした
          // どこからの後退辺かは分からないのでそのまま戻ってくる
          dat[v][i].tp = BACK_UP;
          GO(LAST());
          continue;
        }
        if (Color() == 1) {
          // 新しい頂点発見
          dat[v][i].tp = TREE_DOWN;
          dat[v][i].to = new_v(v);
          dfs(dfs, dat[v][i].to);
        }
        if (Color() == 3) {
          dat[v][i].tp = BACK_DOWN;
          GO(LAST());
          continue;
        }
      }
      change_color(3);
      if (v > 0) GO(last);
    };
    dfs(dfs, 0);
  }

  int N = n;
  vvc<int> digit(N);
  for (int i = 0; i < N; ++i) {
    int x = i;
    for (int j = 0; j < 5; ++j) digit[i].emplace_back(x % 3), x /= 3;
  }

  vc<int> POW = {1, 3, 9, 27, 81};

  for (int keta = 0; keta < 5; ++keta) {
    auto dfs = [&](auto& dfs, int v) -> void {
      int d = dat[v].size();
      int last = LAST();
      change_color(digit[v][keta] + 1);
      for (int i = 0; i < d; ++i) {
        if (dat[v][i].tp == TREE_UP) continue;
        if (dat[v][i].tp == BACK_DOWN) continue;
        if (dat[v][i].tp == TREE_DOWN) {
          GO(i);
          dfs(dfs, dat[v][i].to);
          continue;
        }
        if (dat[v][i].tp == BACK_UP) {
          GO(i);
          int k = Color();
          GO(LAST());
          dat[v][i].to += POW[keta] * (k - 1);
        }
      }
      if (v > 0) GO(last);
    };
    dfs(dfs, 0);
  }

  // 全部わかったはず
  vvc<int> D(N, vc<int>(N));
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < N; ++j) D[i][j] = (i == j ? 0 : 1 << 20);

  vvc<int> G(N);
  for (int v = 0; v < N; ++v) {
    for (auto& X: dat[v]) {
      if (X.tp == BACK_DOWN) continue;
      int w = X.to;
      D[v][w] = D[w][v] = 1;
    }
  }
  for (int t = 0; t < 3; ++t) {
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < N; ++j) {
        for (int k = 0; k < N; ++k) { D[i][k] = min(D[i][k], D[i][j] + D[j][k]); }
      }
    }
  }
  vc<int> ANS(N + 1);
  for (int i = 0; i < N; ++i) {
    for (int j = i + 1; j < N; ++j) ANS[D[i][j]]++;
  }
  for (int i = 1; i <= R; ++i) Answer(i, ANS[i]);
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 0
Runtime Error

input:

10 100 50
7
5 7 10 4 6 2 3
2
1 5
3
1 10 7
2
10 1
3
1 9 2
2
1 7
5
9 6 8 3 1
1
7
2
5 7
3
1 4 3
15
24
6
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

output:

Wrong Answer [4]

result:


Subtask #2:

score: 0
Runtime Error

Test #16:

score: 0
Runtime Error

input:

10 3 50
4
7 4 10 5
2
8 6
1
10
2
1 9
3
1 7 10
2
7 2
5
6 1 5 8 9
3
7 9 2
4
10 8 7 4
4
1 9 5 3
15
19
9
2
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

output:

Wrong Answer [4]

result:


Subtask #3:

score: 0
Runtime Error

Test #31:

score: 56
Accepted
time: 18ms
memory: 4556kb

input:

200 3 200
6
149 79 143 164 179 68
4
44 52 144 113
1
84
3
31 188 166
1
109
4
154 192 125 147
1
198
4
103 27 192 95
3
33 166 179
1
125
3
31 61 150
3
168 152 161
2
67 64
1
136
2
150 17
1
192
2
15 142
2
56 122
1
35
2
97 200
2
129 22
4
72 134 31 21
2
53 82
4
195 181 104 146
1
78
1
88
3
8 78 127
4
152 200...

output:

Accepted: #move = 2542

result:

points 1.0 L = 12.104761904762

Test #32:

score: 56
Accepted
time: 14ms
memory: 4220kb

input:

200 3 200
8
149 79 143 164 179 68 5 54
4
44 52 113 144
2
152 84
3
166 188 31
3
1 149 109
6
125 192 140 147 154 182
1
198
6
29 103 95 27 192 44
3
166 33 179
5
105 189 125 120 79
3
150 61 31
5
161 179 152 168 186
3
124 67 64
2
136 104
2
17 150
2
93 192
3
142 21 15
5
122 47 56 62 29
1
35
2
97 200
4
22 ...

output:

Accepted: #move = 3802

result:

points 1.0 L = 12.673333333333

Test #33:

score: 56
Accepted
time: 18ms
memory: 4300kb

input:

200 3 200
11
149 79 143 164 179 190 5 54 123 22 68
11
43 6 165 52 44 45 144 197 113 142 96
9
74 182 152 49 84 128 26 106 22
12
188 66 50 127 9 104 31 166 128 123 191 43
9
179 128 60 13 149 47 109 1 178
13
81 23 84 31 67 192 154 182 125 140 2 147 51
7
198 155 32 123 27 169 171
12
27 106 157 192 174 9...

output:

Accepted: #move = 13602

result:

points 1.0 L = 13.602000000000

Test #34:

score: 56
Accepted
time: 23ms
memory: 4592kb

input:

200 3 200
198
116 13 87 107 11 78 74 63 61 37 25 98 130 91 179 53 16 122 140 114 182 23 191 75 67 49 5 190 161 134 156 129 160 35 118 149 76 115 73 97 166 174 4 153 9 27 192 68 72 90 56 126 196 10 165 169 12 86 112 154 69 85 180 104 83 105 171 170 197 28 21 40 128 186 93 181 187 71 119 145 111 100 1...

output:

Accepted: #move = 276802

result:

points 1.0 L = 13.979898989899

Test #35:

score: 0
Runtime Error

input:

64 3 200
6
33 28 46 15 58 60
6
4 9 7 29 6 23
6
26 55 24 60 47 15
6
2 60 10 55 62 28
6
46 59 33 57 42 37
6
62 13 27 40 2 50
6
10 37 2 19 27 59
6
11 32 47 51 24 30
6
60 2 37 26 13 33
6
7 41 4 44 49 48
6
8 34 14 16 52 64
6
57 56 15 46 30 24
6
53 6 16 14 9 18
6
47 40 11 13 26 25
6
35 17 12 1 61 3
6
51 2...

output:

Wrong Answer [4]

result: