Submission #375338

#TimeUsernameProblemLanguageResultExecution timeMemory
375338KoDDungeon 2 (JOI16_dungeon2)C++17
100 / 100
100 ms1516 KiB
#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 < 5; ++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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...