Submission #375335

# Submission time Handle Problem Language Result Execution time Memory
375335 2021-03-09T09:23:38 Z KoD None (JOI16_dungeon2) C++17
44 / 100
19 ms 1004 KB
#include <bits/stdc++.h>
#include "dungeon2.h"

template <class T>
using Vec = std::vector<T>;

template <class F>
struct RecLambda: private F {
	explicit RecLambda(F &&f): F(std::forward<F>(f)) { }
	template <class... Args>
	decltype(auto) operator () (Args&&... args) const {
		return F::operator()(*this, std::forward<Args>(args)...);
	}
};

constexpr int POW3[] = { 1, 3, 9, 27, 81 };

void Inspect(int R) {
	Vec<Vec<int>> graph;
	Vec<Vec<int>> id;
	Vec<int> p_edge;
	RecLambda([&](auto dfs, const int p) -> int {
		const auto u = (int) graph.size();
		graph.push_back(Vec<int>(NumberOfRoads()));
		id.push_back(Vec<int>(NumberOfRoads()));
		p_edge.push_back(LastRoad() - 1);
		if (p != -1) {
			graph[u][p_edge[u]] = 3;
		}
		for (int i = 0; i < (int) graph[u].size(); ++i) {
			if (graph[u][i] != 0) {
				continue;
			}
			Move(i + 1, 2);
			if (Color() == 2) {
				Move(LastRoad(), 2);
				graph[u][i] = 2;
			}
			else if (Color() == 3) {
				Move(LastRoad(), 3);
				graph[u][i] = 3;
			}
			else {
				graph[u][i] = 1;
				id[u][i] = dfs(u);
			}
		}
		if (p != -1) {
			Move(p_edge[u] + 1, 3);
		}
		return u;
	})(-1);
	const auto N = (int) graph.size();
	const auto dfs = RecLambda([&](auto dfs, const int u, const int step) -> void {
		const auto write = (u / POW3[step]) % 3;
		for (int i = 0; i < (int) graph[u].size(); ++i) {
			if (graph[u][i] == 1) {
				Move(i + 1, write + 1);
				dfs(id[u][i], step);
			}
			else if (graph[u][i] == 2) {
				Move(i + 1, write + 1);
				id[u][i] += POW3[step] * (Color() - 1);
				Move(LastRoad(), Color()); 
			}
		}
		if (p_edge[u] >= 0) {
			Move(p_edge[u] + 1, write + 1);
		}
	});
	for (int i = 0; i < 4; ++i) {
		dfs(0, i);
	}
	Vec<Vec<int>> dist(N, Vec<int>(N, N));
	for (int u = 0; u < N; ++u) {
		dist[u][u] = 0;
		for (int i = 0; i < (int) graph[u].size(); ++i) {
			if (graph[u][i] <= 2) {
				const auto v = id[u][i];
				dist[u][v] = 1;
				dist[v][u] = 1;
			}
		}
	}
	for (int k = 0; k < N; ++k) {
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				dist[i][j] = std::min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}
	for (int d = 1; d <= R; ++d) {
		int ans = 0;
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < i; ++j) {
				if (dist[i][j] == d) {
					ans += 1;
				}
			}
		}
		Answer(d, ans);
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 1004 KB Wrong Answer [4]
2 Halted 0 ms 0 KB -