답안 #926519

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
926519 2024-02-13T08:00:35 Z daoquanglinh2007 Amusement Park (JOI17_amusement_park) C++17
0 / 100
19 ms 5608 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);
				}
				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 1820 KB Output is correct
2 Correct 1 ms 1812 KB Output is correct
3 Correct 1 ms 1824 KB Output is correct
4 Correct 1 ms 1824 KB Output is correct
5 Incorrect 2 ms 2268 KB Wrong Answer [7]
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 5608 KB Output is correct
2 Correct 18 ms 5472 KB Output is correct
3 Correct 17 ms 5376 KB Output is correct
4 Correct 10 ms 3896 KB Output is correct
5 Correct 10 ms 4448 KB Output is correct
6 Correct 11 ms 4160 KB Output is correct
7 Correct 11 ms 4160 KB Output is correct
8 Correct 11 ms 4408 KB Output is correct
9 Correct 11 ms 4416 KB Output is correct
10 Correct 9 ms 3900 KB Output is correct
11 Correct 9 ms 3900 KB Output is correct
12 Correct 10 ms 3876 KB Output is correct
13 Correct 9 ms 3880 KB Output is correct
14 Correct 12 ms 3812 KB Output is correct
15 Correct 12 ms 3904 KB Output is correct
16 Correct 10 ms 3908 KB Output is correct
17 Correct 10 ms 3904 KB Output is correct
18 Correct 11 ms 3960 KB Output is correct
19 Correct 10 ms 3904 KB Output is correct
20 Correct 9 ms 4416 KB Output is correct
21 Correct 9 ms 4412 KB Output is correct
22 Incorrect 13 ms 3904 KB Wrong Answer [7]
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 1824 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 5408 KB Output is correct
2 Correct 18 ms 5408 KB Output is correct
3 Correct 19 ms 5396 KB Output is correct
4 Correct 10 ms 3896 KB Output is correct
5 Correct 11 ms 4664 KB Output is correct
6 Incorrect 11 ms 4416 KB Wrong Answer [7]
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 5408 KB Output is correct
2 Correct 19 ms 5492 KB Output is correct
3 Correct 19 ms 5396 KB Output is correct
4 Correct 10 ms 3900 KB Output is correct
5 Correct 11 ms 4928 KB Output is correct
6 Correct 10 ms 4152 KB Output is correct
7 Correct 10 ms 4240 KB Output is correct
8 Correct 10 ms 4412 KB Output is correct
9 Correct 10 ms 4148 KB Output is correct
10 Correct 10 ms 3908 KB Output is correct
11 Correct 9 ms 3856 KB Output is correct
12 Correct 9 ms 3880 KB Output is correct
13 Correct 9 ms 3880 KB Output is correct
14 Correct 9 ms 3880 KB Output is correct
15 Correct 10 ms 3896 KB Output is correct
16 Correct 10 ms 3972 KB Output is correct
17 Correct 10 ms 3896 KB Output is correct
18 Correct 10 ms 3896 KB Output is correct
19 Correct 10 ms 3900 KB Output is correct
20 Correct 9 ms 4408 KB Output is correct
21 Correct 9 ms 4408 KB Output is correct
22 Correct 13 ms 4096 KB Output is correct
23 Correct 10 ms 3904 KB Output is correct
24 Correct 10 ms 3908 KB Output is correct
25 Correct 10 ms 3904 KB Output is correct
26 Correct 12 ms 3896 KB Output is correct
27 Correct 10 ms 4408 KB Output is correct
28 Correct 14 ms 4404 KB Output is correct
29 Correct 13 ms 3924 KB Output is correct
30 Correct 11 ms 3880 KB Output is correct
31 Correct 1 ms 1808 KB Output is correct
32 Correct 1 ms 1824 KB Output is correct
33 Correct 1 ms 1828 KB Output is correct
34 Correct 1 ms 1812 KB Output is correct
35 Incorrect 1 ms 1828 KB Wrong Answer [7]
36 Halted 0 ms 0 KB -