답안 #211817

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
211817 2020-03-21T12:29:47 Z youngyojun Dungeon 2 (JOI16_dungeon2) C++11
100 / 100
29 ms 3576 KB
#include "dungeon2.h"
#include <bits/stdc++.h>
#define pb push_back
#define sz(V) ((int)(V).size())
#define upmin(a,b) (a)=min((a),(b))
#define INF (0x3f3f3f3f)
using namespace std;
 
const int MAXN = 205;
 
vector<int> G[MAXN];
vector<bool> GD[MAXN];
vector<vector<int>> GC[MAXN];
 
int D[MAXN][MAXN];
int Ans[MAXN];
 
int N, K, CDG;
 
int getColor(int n, int k) {
	for(; k; k--) n /= 3;
	return n % 3 + 1;
}
 
int getIndex(vector<int> &V) {
	int ret = 0;
	for(int k = 4; 0 <= k; k--)
		ret = ret * 3 + (V[k] - 1);
	return ret;
}
 
int f(int pv) {
	const int idx = ++N;
	const int dg = NumberOfRoads();
	const int li = LastRoad();
	G[idx].resize(dg+1, 0);
	GD[idx].resize(dg+1, false);
	GC[idx].resize(dg+1, vector<int>(6, 0));
 
	if(1 <= li && 1 <= pv) {
		G[idx][li] = pv;
	}
 
	for(int i = 1; i <= dg; i++) {
		if(G[idx][i]) continue;
 
		Move(i, 2);
		if(2 == Color()) {
			G[idx][i] = -1;
			GD[idx][i] = true;
			Move(LastRoad(), 2);
			continue;
		} else if(3 == Color()) {
			G[idx][i] = -2;
			GD[idx][i] = true;
			Move(LastRoad(), 3);
			continue;
		}
 
		G[idx][i] = f(idx);
	}
 
	if(1 <= li) Move(li, 3);
	return idx;
}
 
void g(int idx, int pv) {
	const int dg = NumberOfRoads();
	const int col = getColor(idx, CDG);
	const int li = LastRoad();
 
	for(int i = 1; i <= dg; i++) {
		if(pv == G[idx][i]) continue;
		if(-2 == G[idx][i]) continue;
		if(1 <= G[idx][i]) {
			if(GD[idx][i]) continue;
			Move(i, col);
			g(G[idx][i], idx);
			continue;
		}
 
		Move(i, col);
		GC[idx][i][CDG] = Color();
 
		if(4 == CDG) {
			const int nidx = getIndex(GC[idx][i]);
			G[nidx][LastRoad()] = idx;
			G[idx][i] = nidx;
		}
 
		Move(LastRoad(), Color());
	}
 
	if(1 != idx && 1 <= li)
		Move(li, col);
}
 
void Inspect(int K) {
	::K = K;
	f(-1);
 
	for(int i = 0; i < 5; i++) {
		CDG = i;
		g(1, -INF);
	}

	for(int i = 1; i <= N; i++) fill(D[i], D[i]+N+1, INF);
	for(int i = 1; i <= N; i++) D[i][i] = 0;
	for(int i = 1; i <= N; i++) {
		for(int v : G[i]) {
			if(v < 1 || N < v) continue;
			D[i][v] = D[v][i] = 1;
		}
	}
 
	for(int k = 1; k <= N; k++) for(int i = 1; i <= N; i++) for(int j = 1; j <= N; j++)
		upmin(D[i][j], D[i][k] + D[k][j]);
	
	for(int i = 1; i <= N; i++) for(int j = i+1; j <= N; j++)
		Ans[D[i][j]]++;
	
	for(int i = 1; i <= K; i++)
		Answer(i, Ans[i]);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 5 ms 512 KB Output is correct
5 Correct 5 ms 512 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 5 ms 512 KB Output is correct
10 Correct 5 ms 512 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 5 ms 512 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 5 ms 512 KB Output is correct
4 Correct 5 ms 560 KB Output is correct
5 Correct 5 ms 512 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 5 ms 512 KB Output is correct
10 Correct 5 ms 512 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 5 ms 512 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 1024 KB Output is correct
2 Correct 14 ms 1024 KB Output is correct
3 Correct 16 ms 1152 KB Output is correct
4 Correct 29 ms 3576 KB Output is correct
5 Correct 5 ms 640 KB Output is correct
6 Correct 8 ms 800 KB Output is correct
7 Correct 14 ms 1024 KB Output is correct
8 Correct 14 ms 1024 KB Output is correct
9 Correct 14 ms 1024 KB Output is correct
10 Correct 14 ms 1024 KB Output is correct
11 Correct 14 ms 1024 KB Output is correct
12 Correct 14 ms 1024 KB Output is correct
13 Correct 17 ms 1408 KB Output is correct
14 Correct 14 ms 896 KB Output is correct
15 Correct 14 ms 1024 KB Output is correct
16 Correct 9 ms 1280 KB Output is correct
17 Correct 28 ms 3456 KB Output is correct
18 Correct 27 ms 3328 KB Output is correct
19 Correct 27 ms 3328 KB Output is correct