답안 #695244

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
695244 2023-02-04T20:15:19 Z rainboy Dungeon 2 (JOI16_dungeon2) C++17
100 / 100
16 ms 1124 KB
#include "dungeon2.h"
#include <stdlib.h>
#include <string.h>

const int N = 200, L = 5;	/* L = ceil(log3(N + 1)) */

int pp3[L + 1];

void init() {
	pp3[0] = 1;
	for (int l = 1; l <= L; l++)
		pp3[l] = pp3[l - 1] * 3;
}

int *ej[N + 1], eo[N + 1], ff[N + 1], n; char *et[N + 1];

void dfs1(int i) {
	eo[i] = NumberOfRoads();
	ej[i] = (int *) malloc((eo[i] + 1) * sizeof *ej[i]);
	et[i] = (char *) malloc((eo[i] + 1) * sizeof *et[i]);
	ff[i] = LastRoad();
	for (int o = 1; o <= eo[i]; o++)
		if (o != ff[i]) {
			Move(o, 2);
			if (Color() == 1) {
				int j = ++n;
				ej[i][o] = j, et[i][o] = 0, dfs1(j), Move(ff[j], 3);
			} else if (Color() == 2)
				ej[i][o] = 0, et[i][o] = 1, Move(LastRoad(), Color());
			else
				ej[i][o] = 0, et[i][o] = 2, Move(LastRoad(), Color());
		} else
			ej[i][o] = 0, et[i][o] = 2;
}

void dfs2(int i, int l) {
	for (int o = 1; o <= eo[i]; o++) {
		int j = ej[i][o], t = et[i][o];
		if (t == 0)
			Move(o, i / pp3[l] % 3 + 1), dfs2(j, l), Move(ff[j], j / pp3[l] % 3 + 1);
		else if (t == 1)
			Move(o, i / pp3[l] % 3 + 1), ej[i][o] += pp3[l] * (Color() - 1), Move(LastRoad(), Color());
	}
}

int dd[N + 1], ans[N + 1];

void bfs(int s) {
	static int qu[N + 1];
	for (int i = 1; i <= n; i++)
		dd[i] = n;
	int cnt = 0;
	dd[s] = 0, qu[cnt++] = s;
	for (int h = 0; h < cnt; h++) {
		int i = qu[h], d = dd[i] + 1;
		for (int o = 1; o <= eo[i]; o++) {
			int j = ej[i][o];
			if (dd[j] > d)
				dd[j] = d, qu[cnt++] = j;
		}
	}
}

void find_graph() {
	n = 1, dfs1(1);
	for (int l = 0; l < L; l++)
		dfs2(1, l);
	for (int i = 1; i <= n; i++)
		for (int o = 1; o <= eo[i]; o++)
			if (et[i][o] == 0 || et[i][o] == 1) {
				int j = ej[i][o];
				for (int o_ = 1; o_ <= eo[j]; o_++)
					if (et[j][o_] == 2) {
						et[j][o_] = -1, ej[j][o_] = i;
						break;
					}
			}
}

void Inspect(int d_) {
	init();
	find_graph();
	memset(ans, 0, (n + 1) * sizeof *ans);
	for (int i = 1; i <= n; i++) {
		bfs(i);
		for (int j = i + 1; j <= n; j++)
			ans[dd[j]]++;
	}
	for (int d = 1; d <= d_; d++)
		Answer(d, ans[d]);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 292 KB Output is correct
7 Correct 0 ms 288 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 288 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 288 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 292 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 292 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 2 ms 724 KB Output is correct
3 Correct 2 ms 724 KB Output is correct
4 Correct 16 ms 1112 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 2 ms 724 KB Output is correct
9 Correct 2 ms 724 KB Output is correct
10 Correct 2 ms 768 KB Output is correct
11 Correct 1 ms 724 KB Output is correct
12 Correct 2 ms 680 KB Output is correct
13 Correct 4 ms 724 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 724 KB Output is correct
16 Correct 4 ms 596 KB Output is correct
17 Correct 16 ms 1068 KB Output is correct
18 Correct 14 ms 1124 KB Output is correct
19 Correct 14 ms 1108 KB Output is correct