답안 #27162

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
27162 2017-07-09T17:44:57 Z abcdef6199 Dungeon 2 (JOI16_dungeon2) C++11
100 / 100
33 ms 3200 KB
#include "dungeon2.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<int, int> II;

const int MAXN = 200 + 10;
int n, a[MAXN][MAXN];
int ans[MAXN][MAXN];
vector<II> adj[MAXN];
vector<int> ret[MAXN];

void Build(int u) {
	int deg = NumberOfRoads();
	int pre = LastRoad();
	for (int i = 1; i <= deg; ++i) if (i != pre) {
		Move(i, 2);
		int x = LastRoad();
		if (Color() == 1) {
			adj[u].push_back(II(++n, i));
			Build(n);
			Move(x, 3);
		}
		else {
			int c = Color();
			if (c == 2) ret[u].push_back(i);
			Move(x, c);
		}
	}
}

void DFS(int u, int pw, vector<int> ver) {
	int h = (int) ver.size();
	for (int j = 0; j < (int) ret[u].size(); ++j) {
		int i = ret[u][j];
		Move(i, h % (pw * 3) / pw + 1);
		int x = LastRoad();
		int c = Color();
		ans[u][i] += pw * (c - 1);
		Move(x, c);
		if (pw == 81) {
			int v = ver[ans[u][i]];
			a[u][v] = 1;
			a[v][u] = 1;
		}
	}
	ver.push_back(u);
	for (int j = 0; j < (int) adj[u].size(); ++j) {
		int i = adj[u][j].second;
		Move(i, h % (pw * 3) / pw + 1);
		int x = LastRoad();
		DFS(adj[u][j].first, pw, ver);
		Move(x, Color());
	}
	ver.pop_back();
}

void Inspect(int R) {
	n = 1; Build(1);
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n; ++j) a[i][j] = 100000;
		a[i][i] = 0;
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j < (int) adj[i].size(); ++j) {
			int x = adj[i][j].first;
			a[i][x] = 1;
			a[x][i] = 1;
		}
	}
	DFS(1,  1, vector<int>(0, 0));
	DFS(1,  3, vector<int>(0, 0));
	DFS(1,  9, vector<int>(0, 0));
	DFS(1, 27, vector<int>(0, 0));
	DFS(1, 81, vector<int>(0, 0));

	for (int k = 1; k <= n; ++k)
		for (int i = 1; i <= n; ++i)
			for (int j = 1; j <= n; ++j)
				a[i][j] = min(a[i][j], a[i][k] + a[k][j]);
	for (int i = 1; i <= R; ++i) {
		int ans = 0;
		for (int u = 1; u <= n; ++u)
			for (int v = u + 1; v <= n; ++v)
				if (a[u][v] == i) ans++;
		Answer(i, ans);
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2868 KB Output is correct
2 Correct 0 ms 2868 KB Output is correct
3 Correct 0 ms 2868 KB Output is correct
4 Correct 0 ms 2868 KB Output is correct
5 Correct 0 ms 2868 KB Output is correct
6 Correct 0 ms 2868 KB Output is correct
7 Correct 0 ms 2868 KB Output is correct
8 Correct 0 ms 2868 KB Output is correct
9 Correct 0 ms 2868 KB Output is correct
10 Correct 0 ms 2868 KB Output is correct
11 Correct 0 ms 2868 KB Output is correct
12 Correct 0 ms 2868 KB Output is correct
13 Correct 0 ms 2868 KB Output is correct
14 Correct 0 ms 2868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2868 KB Output is correct
2 Correct 0 ms 2868 KB Output is correct
3 Correct 0 ms 2868 KB Output is correct
4 Correct 0 ms 2868 KB Output is correct
5 Correct 0 ms 2868 KB Output is correct
6 Correct 0 ms 2868 KB Output is correct
7 Correct 0 ms 2868 KB Output is correct
8 Correct 0 ms 2868 KB Output is correct
9 Correct 0 ms 2868 KB Output is correct
10 Correct 0 ms 2868 KB Output is correct
11 Correct 0 ms 2868 KB Output is correct
12 Correct 0 ms 2868 KB Output is correct
13 Correct 0 ms 2868 KB Output is correct
14 Correct 0 ms 2868 KB Output is correct
15 Correct 0 ms 2868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 2868 KB Output is correct
2 Correct 16 ms 3000 KB Output is correct
3 Correct 16 ms 3000 KB Output is correct
4 Correct 33 ms 3200 KB Output is correct
5 Correct 0 ms 2868 KB Output is correct
6 Correct 3 ms 3000 KB Output is correct
7 Correct 16 ms 3000 KB Output is correct
8 Correct 16 ms 2868 KB Output is correct
9 Correct 26 ms 2868 KB Output is correct
10 Correct 13 ms 3000 KB Output is correct
11 Correct 16 ms 3000 KB Output is correct
12 Correct 19 ms 3000 KB Output is correct
13 Correct 19 ms 3000 KB Output is correct
14 Correct 16 ms 2868 KB Output is correct
15 Correct 16 ms 3000 KB Output is correct
16 Correct 3 ms 3000 KB Output is correct
17 Correct 33 ms 3196 KB Output is correct
18 Correct 29 ms 3192 KB Output is correct
19 Correct 23 ms 3192 KB Output is correct