#include "dungeon2.h"
#include <bits/stdc++.h>
#define MAX 250
using namespace std;
typedef pair<int, int> pii;
vector<pii> tree[MAX], down[MAX];
vector<int> backe[MAX], adj[MAX];
int prt[MAX];
int prtl[MAX];
int ans[MAX];
int dist[MAX][MAX];
int pow3[6] = { 1, 3, 9, 27, 81, 243 };
int cnt = 1;
void dfs(int x = 1, int p = 0, int pv = -1) {
prt[x] = p;
prtl[x] = pv;
int deg = NumberOfRoads();
int i;
for (i = 1; i <= deg; i++) if (i != pv) {
Move(i, 2);
if (Color() == 2) backe[x].push_back(i), Move(LastRoad(), 2);
else cnt++, tree[x].emplace_back(cnt, i), dfs(cnt, x, LastRoad());
}
if (x > 1) Move(pv, 2);
}
void updown(int x = 1) {
for (auto v : backe[x]) {
Move(v, 1);
if (Color() != 1) down[x].emplace_back(0, v);
Move(LastRoad(), Color());
}
for (auto& [v, e] : tree[x]) {
Move(e, 1);
updown(v);
}
if (x > 1) Move(prtl[x], 1);
}
int getv(int x, int k) {
while (k--) x /= 3;
return (x % 3) + 1;
}
void upd(int x, int k) {
for (auto& [v, e] : tree[x]) {
Move(e, getv(x, k));
upd(v, k);
}
if (x > 1) Move(prtl[x], getv(x, k));
}
void addv(int x, int k) {
for (auto& [v, e] : down[x]) {
Move(e, Color());
v += pow3[k] * (Color() - 1);
Move(LastRoad(), Color());
}
for (auto& [v, e] : tree[x]) {
Move(e, Color());
addv(v, k);
}
if (x > 1) Move(prtl[x], Color());
}
void getdis(int x) {
queue<int> q;
q.push(x);
while (q.size()) {
int t = q.front();
q.pop();
for (auto v : adj[t]) {
if (!dist[x][v]) {
dist[x][v] = dist[x][t] + 1;
q.push(v);
}
}
}
}
void Inspect(int R) {
dfs();
updown();
for (int k = 0; k < 6; k++) upd(1, k), addv(1, k);
int i, j;
for (i = 1; i <= cnt; i++) for (auto& [v, e] : down[i]) adj[i].push_back(v), adj[v].push_back(i);
for (i = 1; i <= cnt; i++) for (auto& [v, e] : tree[i]) adj[i].push_back(v), adj[v].push_back(i);
for (i = 1; i <= cnt; i++) getdis(i);
for (i = 1; i <= cnt; i++) for (j = i + 1; j <= cnt; j++) ans[dist[i][j]]++;
for (i = 1; i <= R; i++) Answer(i, ans[i]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
464 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
464 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
464 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
472 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
2 ms |
852 KB |
Partially correct |
2 |
Partially correct |
2 ms |
852 KB |
Partially correct |
3 |
Partially correct |
3 ms |
980 KB |
Partially correct |
4 |
Partially correct |
23 ms |
1816 KB |
Partially correct |
5 |
Partially correct |
1 ms |
468 KB |
Partially correct |
6 |
Partially correct |
1 ms |
724 KB |
Partially correct |
7 |
Partially correct |
1 ms |
980 KB |
Partially correct |
8 |
Partially correct |
2 ms |
980 KB |
Partially correct |
9 |
Partially correct |
2 ms |
980 KB |
Partially correct |
10 |
Partially correct |
2 ms |
980 KB |
Partially correct |
11 |
Partially correct |
2 ms |
980 KB |
Partially correct |
12 |
Partially correct |
3 ms |
980 KB |
Partially correct |
13 |
Partially correct |
5 ms |
1108 KB |
Partially correct |
14 |
Partially correct |
2 ms |
852 KB |
Partially correct |
15 |
Partially correct |
2 ms |
980 KB |
Partially correct |
16 |
Partially correct |
3 ms |
852 KB |
Partially correct |
17 |
Partially correct |
17 ms |
1876 KB |
Partially correct |
18 |
Partially correct |
15 ms |
1752 KB |
Partially correct |
19 |
Partially correct |
17 ms |
1816 KB |
Partially correct |