Submission #641656

# Submission time Handle Problem Language Result Execution time Memory
641656 2022-09-17T11:21:21 Z flappybird None (JOI16_dungeon2) C++17
100 / 100
18 ms 1364 KB
#include "dungeon2.h"
#include <bits/stdc++.h>
#define MAX 250

using namespace std;
typedef pair<int, int> pii;

vector<pii> tree[MAX], up[MAX];
vector<int> backe[MAX], adj[MAX];
int prt[MAX];
int prtl[MAX];
int ans[MAX];
int dist[MAX][MAX];

int pow3[6] = { 1, 3, 9, 27, 81, 243 };

int cnt = 1;

void dfs(int x = 1, int p = 0, int pv = -1) {
	prt[x] = p;
	prtl[x] = pv;
	int deg = NumberOfRoads();
	int i;
	for (i = 1; i <= deg; i++) if (i != pv) {
		Move(i, 2);
		if (Color() == 2) up[x].emplace_back(0, i), Move(LastRoad(), 2);
		else if (Color() == 3) Move(LastRoad(), Color());
		else if (Color() == 1) cnt++, tree[x].emplace_back(cnt, i), dfs(cnt, x, LastRoad());
	}
	if (x > 1) Move(pv, 3);
}

int getv(int x, int k) {
	while (k--) x /= 3;
	return (x % 3) + 1;
}

void addv(int x, int k) {
	for (auto& [v, e] : up[x]) {
		Move(e, getv(x, k));
		v += pow3[k] * (Color() - 1);
		Move(LastRoad(), Color());
	}
	for (auto& [v, e] : tree[x]) {
		Move(e, getv(x, k));
		addv(v, k);
	}
	if (x > 1) Move(prtl[x], getv(x, k));
}

void getdis(int x) {
	queue<int> q;
	q.push(x);
	while (q.size()) {
		int t = q.front();
		q.pop();
		for (auto v : adj[t]) {
			if (!dist[x][v]) {
				dist[x][v] = dist[x][t] + 1;
				q.push(v);
			}
		}
	}
}

void Inspect(int R) {
	dfs();
	for (int k = 0; k < 5; k++) addv(1, k);
	int i, j;
	for (i = 1; i <= cnt; i++) for (auto& [v, e] : up[i]) adj[i].push_back(v), adj[v].push_back(i);
	for (i = 1; i <= cnt; i++) for (auto& [v, e] : tree[i]) adj[i].push_back(v), adj[v].push_back(i);
	for (i = 1; i <= cnt; i++) getdis(i);
	for (i = 1; i <= cnt; i++) for (j = i + 1; j <= cnt; j++) ans[dist[i][j]]++;
	for (i = 1; i <= R; i++) Answer(i, ans[i]);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 0 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 0 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 852 KB Output is correct
2 Correct 2 ms 852 KB Output is correct
3 Correct 2 ms 980 KB Output is correct
4 Correct 15 ms 1328 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
7 Correct 1 ms 904 KB Output is correct
8 Correct 2 ms 852 KB Output is correct
9 Correct 2 ms 852 KB Output is correct
10 Correct 2 ms 852 KB Output is correct
11 Correct 2 ms 980 KB Output is correct
12 Correct 2 ms 852 KB Output is correct
13 Correct 4 ms 980 KB Output is correct
14 Correct 1 ms 852 KB Output is correct
15 Correct 2 ms 852 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 15 ms 1364 KB Output is correct
18 Correct 18 ms 1316 KB Output is correct
19 Correct 13 ms 1364 KB Output is correct