답안 #926526

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
926526 2024-02-13T08:09:28 Z daoquanglinh2007 Amusement Park (JOI17_amusement_park) C++17
100 / 100
20 ms 5132 KB
#include "Joi.h"
#include <bits/stdc++.h>
using namespace std;

#define ll long long

const int NM = 1e4;

namespace _Joi{
	vector <int> g[NM+5], son[NM+5];
	int parent[NM+5], dep[NM+5];
	bool vis[NM+5], in_max_path[NM+5];
	int MAX_DEP = 0, cnt = 0;
	
	void dfs(int u, int p){
		parent[u] = p;
		if (p != -1) son[p].push_back(u);
		dep[u] = (p == -1 ? 0 : dep[p]+1);
		MAX_DEP = max(MAX_DEP, dep[u]);
		vis[u] = 1;
		for (int v : g[u]){
			if (vis[v]) continue;
			dfs(v, u);
		}
	}
	void build(int u, ll X){
		cnt++;
		MessageBoard(u, (X>>(cnt-1))&1);
		vis[u] = 1;
		for (int v : son[u]){
			if (!in_max_path[v]) continue;
			build(v, X);
		}
		for (int v : son[u]){
			if (in_max_path[v]) continue;
			if (cnt < 60) build(v, X);
		}
	}
	void solve(int N, int M, int A[], int B[], ll X, int T){
		assert(T >= 1 && T <= 5);
		for (int i = 0; i < M; i++){
			g[A[i]].push_back(B[i]);
			g[B[i]].push_back(A[i]);
		}
		dfs(0, -1);
		if (MAX_DEP >= 60){
			for (int i = 0; i < N; i++)
				MessageBoard(i, (X>>(dep[i]%60))&1);
			return;
		}
		bool found = 0;
		for (int i = 0; i < N; i++)
			if (dep[i] == MAX_DEP && !found){
				found = 1;
				for (int j = i; j != -1; j = parent[j]){
					in_max_path[j] = 1;
				}
			}
		for (int i = 0; i < N; i++) vis[i] = 0;
		build(0, X);
		for (int i = 0; i < N; i++)
			if (!vis[i]) MessageBoard(i, 0);
	}
}

void Joi(int N, int M, int A[], int B[], ll X, int T){
	_Joi::solve(N, M, A, B, X, T);
}
#include "Ioi.h"
#include <bits/stdc++.h>
using namespace std;

#define ll long long

const int NM = 1e4;

namespace _Ioi{
	vector <int> g[NM+5], son[NM+5];
	int parent[NM+5], dep[NM+5];
	bool vis[NM+5], in_max_path[NM+5];
	int MAX_DEP = 0, cnt = 0;
	int L[NM+5], f[NM+5];
	ll X = 0;
	
	void dfs(int u, int p){
		parent[u] = p;
		if (p != -1) son[p].push_back(u);
		dep[u] = (p == -1 ? 0 : dep[p]+1);
		MAX_DEP = max(MAX_DEP, dep[u]);
		vis[u] = 1;
		for (int v : g[u]){
			if (vis[v]) continue;
			dfs(v, u);
		}
	}
	void build(int u){
		cnt++;
		L[u] = cnt-1;
		for (int v : son[u]){
			if (!in_max_path[v]) continue;
			build(v);
		}
		for (int v : son[u]){
			if (in_max_path[v]) continue;
			if (cnt < 60) build(v);
		}
	}
	void calc(int u){
		f[u] = dep[u];
		for (int v : son[u]){
			calc(v);
			f[u] = max(f[u], f[v]);
		}
	}
	void get_ans(int u, int val){
		if (val) X += (1LL<<L[u]);
		for (int v : son[u]){
			if (L[v] == -1) continue;
			if (in_max_path[v]) continue;
			get_ans(v, Move(v));
			Move(u);
		}
		for (int v : son[u]){
			if (L[v] == -1) continue;
			if (!in_max_path[v]) continue;
			get_ans(v, Move(v));
		}
	}
	ll solve(int N, int M, int A[], int B[], int P, int V, int T){
		assert(T >= 1 && T <= 5);
		for (int i = 0; i < M; i++){
			g[A[i]].push_back(B[i]);
			g[B[i]].push_back(A[i]);
		}
		dfs(0, -1);
		if (MAX_DEP >= 60){
			if (dep[P] >= 60){
				if (V) X += (1LL<<(dep[P]%60));
				for (int i = 1; i < 60; i++){
					P = parent[P];
					V = Move(P);
					if (V) X += (1LL<<(dep[P]%60));
				}
			}
			else{
				while (P > 0){
					P = parent[P];
					V = Move(P);
				}
				calc(0);
				if (V) X++;
				for (int i = 1; i < 60; i++){
					for (int nxt : son[P]){
						if (f[nxt] < 59) continue;
						P = nxt;
						V = Move(nxt);
						if (V) X += (1LL<<i);
						break;
					}
				}
			}
			return X;
		}
		bool found = 0;
		for (int i = 0; i < N; i++)
			if (dep[i] == MAX_DEP && !found){
				found = 1;
				for (int j = i; j != -1; j = parent[j]){
					in_max_path[j] = 1;
				}
			}
		for (int i = 0; i < N; i++) L[i] = -1;
		build(0);
		while (P > 0){
			P = parent[P];
			V = Move(P);
		}
		get_ans(0, V);
		return X;
	}
}

ll Ioi(int N, int M, int A[], int B[], int P, int V, int T){
	return _Ioi::solve(N, M, A, B, P, V, T);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1816 KB Output is correct
2 Correct 1 ms 1820 KB Output is correct
3 Correct 1 ms 2064 KB Output is correct
4 Correct 1 ms 1820 KB Output is correct
5 Correct 0 ms 1808 KB Output is correct
6 Correct 1 ms 1820 KB Output is correct
7 Correct 2 ms 1820 KB Output is correct
8 Correct 1 ms 1824 KB Output is correct
9 Correct 1 ms 1816 KB Output is correct
10 Correct 1 ms 1808 KB Output is correct
11 Correct 3 ms 2120 KB Output is correct
12 Correct 1 ms 1820 KB Output is correct
13 Correct 2 ms 1808 KB Output is correct
14 Correct 2 ms 1816 KB Output is correct
15 Correct 1 ms 1824 KB Output is correct
16 Correct 1 ms 1824 KB Output is correct
17 Correct 1 ms 1820 KB Output is correct
18 Correct 2 ms 1816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 4968 KB Output is correct
2 Correct 17 ms 5132 KB Output is correct
3 Correct 17 ms 4952 KB Output is correct
4 Correct 11 ms 3808 KB Output is correct
5 Correct 10 ms 4316 KB Output is correct
6 Correct 11 ms 3808 KB Output is correct
7 Correct 12 ms 3808 KB Output is correct
8 Correct 11 ms 3880 KB Output is correct
9 Correct 10 ms 4056 KB Output is correct
10 Correct 9 ms 3544 KB Output is correct
11 Correct 9 ms 3548 KB Output is correct
12 Correct 9 ms 3780 KB Output is correct
13 Correct 9 ms 3528 KB Output is correct
14 Correct 10 ms 3532 KB Output is correct
15 Correct 11 ms 3796 KB Output is correct
16 Correct 10 ms 3808 KB Output is correct
17 Correct 11 ms 3796 KB Output is correct
18 Correct 10 ms 3808 KB Output is correct
19 Correct 12 ms 3688 KB Output is correct
20 Correct 9 ms 4056 KB Output is correct
21 Correct 9 ms 4060 KB Output is correct
22 Correct 11 ms 3796 KB Output is correct
23 Correct 10 ms 3800 KB Output is correct
24 Correct 10 ms 3800 KB Output is correct
25 Correct 10 ms 4000 KB Output is correct
26 Correct 11 ms 3808 KB Output is correct
27 Correct 13 ms 3944 KB Output is correct
28 Correct 11 ms 3800 KB Output is correct
29 Correct 9 ms 3784 KB Output is correct
30 Correct 11 ms 3796 KB Output is correct
31 Correct 2 ms 1808 KB Output is correct
32 Correct 1 ms 1808 KB Output is correct
33 Correct 1 ms 1824 KB Output is correct
34 Correct 1 ms 1816 KB Output is correct
35 Correct 1 ms 1808 KB Output is correct
36 Correct 1 ms 1808 KB Output is correct
37 Correct 1 ms 1804 KB Output is correct
38 Correct 1 ms 1808 KB Output is correct
39 Correct 1 ms 1808 KB Output is correct
40 Correct 1 ms 1820 KB Output is correct
41 Correct 1 ms 1808 KB Output is correct
42 Correct 1 ms 1808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1820 KB Output is correct
2 Correct 1 ms 1820 KB Output is correct
3 Correct 2 ms 1804 KB Output is correct
4 Correct 2 ms 2352 KB Output is correct
5 Correct 2 ms 2352 KB Output is correct
6 Correct 2 ms 2344 KB Output is correct
7 Correct 2 ms 2196 KB Output is correct
8 Correct 3 ms 2356 KB Output is correct
9 Correct 9 ms 4828 KB Output is correct
10 Correct 10 ms 4900 KB Output is correct
11 Correct 9 ms 4836 KB Output is correct
12 Correct 0 ms 1804 KB Output is correct
13 Correct 1 ms 1820 KB Output is correct
14 Correct 1 ms 1808 KB Output is correct
15 Correct 1 ms 1820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 4956 KB Output is correct
2 Correct 17 ms 4960 KB Output is correct
3 Correct 20 ms 4960 KB Output is correct
4 Correct 10 ms 4056 KB Output is correct
5 Correct 11 ms 4316 KB Output is correct
6 Correct 11 ms 4060 KB Output is correct
7 Correct 11 ms 4064 KB Output is correct
8 Correct 11 ms 3808 KB Output is correct
9 Correct 11 ms 3936 KB Output is correct
10 Correct 9 ms 3504 KB Output is correct
11 Correct 13 ms 3828 KB Output is correct
12 Correct 9 ms 3532 KB Output is correct
13 Correct 9 ms 3528 KB Output is correct
14 Correct 9 ms 3536 KB Output is correct
15 Correct 10 ms 3808 KB Output is correct
16 Correct 10 ms 3792 KB Output is correct
17 Correct 11 ms 3800 KB Output is correct
18 Correct 10 ms 3796 KB Output is correct
19 Correct 11 ms 3796 KB Output is correct
20 Correct 9 ms 4060 KB Output is correct
21 Correct 8 ms 4060 KB Output is correct
22 Correct 10 ms 3808 KB Output is correct
23 Correct 11 ms 3800 KB Output is correct
24 Correct 10 ms 3800 KB Output is correct
25 Correct 10 ms 3804 KB Output is correct
26 Correct 10 ms 4060 KB Output is correct
27 Correct 10 ms 4068 KB Output is correct
28 Correct 10 ms 3796 KB Output is correct
29 Correct 10 ms 3784 KB Output is correct
30 Correct 13 ms 3792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 4988 KB Output is correct
2 Correct 17 ms 5028 KB Output is correct
3 Correct 18 ms 4952 KB Output is correct
4 Correct 12 ms 3812 KB Output is correct
5 Correct 12 ms 4832 KB Output is correct
6 Correct 11 ms 3804 KB Output is correct
7 Correct 11 ms 3804 KB Output is correct
8 Correct 11 ms 4064 KB Output is correct
9 Correct 10 ms 4056 KB Output is correct
10 Correct 9 ms 3544 KB Output is correct
11 Correct 9 ms 3548 KB Output is correct
12 Correct 9 ms 3532 KB Output is correct
13 Correct 10 ms 3540 KB Output is correct
14 Correct 11 ms 3536 KB Output is correct
15 Correct 10 ms 3796 KB Output is correct
16 Correct 10 ms 3800 KB Output is correct
17 Correct 10 ms 3812 KB Output is correct
18 Correct 11 ms 3808 KB Output is correct
19 Correct 11 ms 3672 KB Output is correct
20 Correct 8 ms 4000 KB Output is correct
21 Correct 9 ms 4060 KB Output is correct
22 Correct 10 ms 3800 KB Output is correct
23 Correct 10 ms 3808 KB Output is correct
24 Correct 11 ms 3812 KB Output is correct
25 Correct 10 ms 3800 KB Output is correct
26 Correct 10 ms 3804 KB Output is correct
27 Correct 11 ms 4052 KB Output is correct
28 Correct 13 ms 4052 KB Output is correct
29 Correct 10 ms 3800 KB Output is correct
30 Correct 10 ms 3996 KB Output is correct
31 Correct 1 ms 1804 KB Output is correct
32 Correct 1 ms 2072 KB Output is correct
33 Correct 1 ms 1816 KB Output is correct
34 Correct 1 ms 1804 KB Output is correct
35 Correct 1 ms 1820 KB Output is correct
36 Correct 1 ms 1824 KB Output is correct
37 Correct 2 ms 1804 KB Output is correct
38 Correct 2 ms 1820 KB Output is correct
39 Correct 0 ms 1816 KB Output is correct
40 Correct 1 ms 1816 KB Output is correct
41 Correct 1 ms 1804 KB Output is correct
42 Correct 2 ms 1820 KB Output is correct