#include "dungeon2.h"
#include <bits/stdc++.h>
#define pb push_back
#define sz(V) ((int)(V).size())
#define upmin(a,b) (a)=min((a),(b))
#define INF (0x3f3f3f3f)
using namespace std;
const bool debug = 0;
const int MAXN = 205;
vector<int> G[MAXN];
vector<bool> GD[MAXN];
vector<vector<int>> GC[MAXN];
int D[MAXN][MAXN];
int Ans[MAXN];
int N, K, CDG;
int getColor(int n, int k) {
for(; k; k--) n /= 3;
return n % 3 + 1;
}
int getIndex(vector<int> &V) {
int ret = 0;
for(int k = 4; 0 <= k; k--)
ret = ret * 3 + (V[k] - 1);
return ret;
}
int f(int pv) {
const int idx = ++N;
const int dg = NumberOfRoads();
const int li = LastRoad();
G[idx].resize(dg+1, 0);
GD[idx].resize(dg+1, false);
GC[idx].resize(dg+1, vector<int>(6, 0));
if(1 <= li && 1 <= pv) {
G[idx][li] = pv;
}
for(int i = 1; i <= dg; i++) {
if(G[idx][i]) continue;
Move(i, 2);
if(2 == Color()) {
G[idx][i] = -1;
GD[idx][i] = true;
Move(LastRoad(), 2);
continue;
} else if(3 == Color()) {
G[idx][i] = -2;
GD[idx][i] = true;
Move(LastRoad(), 3);
continue;
}
G[idx][i] = f(idx);
}
if(1 <= li) Move(li, 3);
return idx;
}
void g(int idx, int pv) {
const int dg = NumberOfRoads();
const int col = getColor(idx, CDG);
const int li = LastRoad();
for(int i = 1; i <= dg; i++) {
if(pv == G[idx][i]) continue;
if(-2 == G[idx][i]) continue;
if(1 <= G[idx][i]) {
if(GD[idx][i]) continue;
Move(i, col);
g(G[idx][i], idx);
continue;
}
Move(i, col);
GC[idx][i][CDG] = Color();
if(4 == CDG) {
const int nidx = getIndex(GC[idx][i]);
G[nidx][LastRoad()] = idx;
G[idx][i] = nidx;
}
Move(LastRoad(), Color());
}
if(1 != idx && 1 <= li)
Move(li, col);
}
void Inspect(int K) {
::K = K;
f(-1);
if(debug) {
printf("N=%d\n", N);
for(int i = 1; i <= N; i++) {
printf("%dG : ", i);
for(int v : G[i]) printf("%d ", v);
puts("");
}
//printf("NOW ; %d\n", IAmHere());
}
for(int i = 0; i < 5; i++) {
CDG = i;
g(1, -INF);
//printf("NOW %d ; %d\n", i, IAmHere());
}
if(debug) {
puts("FINAL");
for(int i = 1; i <= N; i++) {
printf("%dG : ", i);
for(int v : G[i]) printf("%d ", v);
puts("");
}
}
for(int i = 1; i <= N; i++) fill(D[i], D[i]+N+1, INF);
for(int i = 1; i <= N; i++) D[i][i] = 0;
for(int i = 1; i <= N; i++) {
for(int v : G[i]) {
if(v < 1 || N < v) continue;
D[i][v] = D[v][i] = 1;
}
}
for(int k = 1; k <= N; k++) for(int i = 1; i <= N; i++) for(int j = 1; j <= N; j++)
upmin(D[i][j], D[i][k] + D[k][j]);
for(int i = 1; i <= N; i++) for(int j = i+1; j <= N; j++)
Ans[D[i][j]]++;
for(int i = 1; i <= K; i++)
Answer(i, Ans[i]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
504 KB |
Output is correct |
2 |
Correct |
3 ms |
504 KB |
Output is correct |
3 |
Correct |
4 ms |
692 KB |
Output is correct |
4 |
Correct |
2 ms |
692 KB |
Output is correct |
5 |
Correct |
3 ms |
692 KB |
Output is correct |
6 |
Correct |
4 ms |
692 KB |
Output is correct |
7 |
Correct |
2 ms |
692 KB |
Output is correct |
8 |
Correct |
3 ms |
692 KB |
Output is correct |
9 |
Correct |
3 ms |
724 KB |
Output is correct |
10 |
Correct |
4 ms |
852 KB |
Output is correct |
11 |
Correct |
3 ms |
852 KB |
Output is correct |
12 |
Correct |
3 ms |
852 KB |
Output is correct |
13 |
Correct |
2 ms |
852 KB |
Output is correct |
14 |
Correct |
4 ms |
852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
852 KB |
Output is correct |
2 |
Correct |
2 ms |
852 KB |
Output is correct |
3 |
Correct |
3 ms |
852 KB |
Output is correct |
4 |
Correct |
3 ms |
852 KB |
Output is correct |
5 |
Correct |
3 ms |
852 KB |
Output is correct |
6 |
Correct |
3 ms |
852 KB |
Output is correct |
7 |
Correct |
3 ms |
852 KB |
Output is correct |
8 |
Correct |
3 ms |
852 KB |
Output is correct |
9 |
Correct |
3 ms |
852 KB |
Output is correct |
10 |
Correct |
2 ms |
852 KB |
Output is correct |
11 |
Correct |
3 ms |
852 KB |
Output is correct |
12 |
Correct |
3 ms |
852 KB |
Output is correct |
13 |
Correct |
3 ms |
852 KB |
Output is correct |
14 |
Correct |
2 ms |
852 KB |
Output is correct |
15 |
Correct |
3 ms |
852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
1132 KB |
Output is correct |
2 |
Correct |
19 ms |
1260 KB |
Output is correct |
3 |
Correct |
17 ms |
1260 KB |
Output is correct |
4 |
Correct |
31 ms |
3564 KB |
Output is correct |
5 |
Correct |
3 ms |
3564 KB |
Output is correct |
6 |
Correct |
6 ms |
3564 KB |
Output is correct |
7 |
Correct |
20 ms |
3564 KB |
Output is correct |
8 |
Correct |
13 ms |
3564 KB |
Output is correct |
9 |
Correct |
13 ms |
3564 KB |
Output is correct |
10 |
Correct |
14 ms |
3564 KB |
Output is correct |
11 |
Correct |
13 ms |
3564 KB |
Output is correct |
12 |
Correct |
13 ms |
3564 KB |
Output is correct |
13 |
Correct |
17 ms |
3564 KB |
Output is correct |
14 |
Correct |
19 ms |
3564 KB |
Output is correct |
15 |
Correct |
14 ms |
3564 KB |
Output is correct |
16 |
Correct |
8 ms |
3564 KB |
Output is correct |
17 |
Correct |
30 ms |
3564 KB |
Output is correct |
18 |
Correct |
31 ms |
3564 KB |
Output is correct |
19 |
Correct |
37 ms |
3564 KB |
Output is correct |