답안 #533114

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
533114 2022-03-04T21:13:49 Z sidon Amusement Park (JOI17_amusement_park) C++17
100 / 100
31 ms 5792 KB
#include <bits/stdc++.h>
#include "Joi.h"
using namespace std;

namespace JOI {
	const int Z = 1e4;

	int L[Z], R[Z], dfsTimer, d[Z], e[Z];
	bool vis[Z];
	vector<int> g[Z], h[Z];

	long long x;

	int init(int u) {
		L[u] = 1;
		for(const int &v : g[u]) if(!L[v]) {
			e[v] = d[v] = d[u] + 1;
			e[u] = max(e[u], init(v));
			h[u].push_back(v);
		}
		sort(begin(h[u]), end(h[u]), [&](const int &i, const int &j) {
			return e[i] > e[j];
		});
		return e[u];
	}

	void dfs(int u) {
		L[u] = ++dfsTimer;
		for(const int &v : h[u]) dfs(v);
		R[u] = 1+dfsTimer;

		MessageBoard(u, bool(x & (1LL<<(L[u] % 60))));
	}
	void Joi(int N, int M, int A[], int B[], long long X, int _T) {
		x = X;
		for(int i = 0; i < M; ++i) {
			g[A[i]].push_back(B[i]);
			g[B[i]].push_back(A[i]);
		}
		init(0);
		dfs(0);
	}
};

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

namespace IOI {
	const int Z = 1e4;

	int L[Z], R[Z], dfsTimer, d[Z], e[Z], p[Z];
	bool vis[Z];
	vector<int> g[Z], h[Z];

	int init(int u) {
		L[u] = ++dfsTimer;
		for(const int &v : g[u]) if(!L[v]) {
			p[v] = u;
			e[v] = d[v] = d[u] + 1;
			e[u] = max(e[u], init(v));
			h[u].push_back(v);
		}
		sort(begin(h[u]), end(h[u]), [&](const int &i, const int &j) {
			return e[i] > e[j];
		});
		R[u] = 1+dfsTimer;
		return e[u];
	}

	int r;
	vector<pair<int, int>> path;

#define valid(X) (L[r] <= X && X < L[r] + 60)

	void dfs(int u) {
		L[u] = ++dfsTimer;
		for(const int &v : h[u]) {
			if(valid(L[u]) && valid(dfsTimer+1))
				path.emplace_back(u, v);
			dfs(v);
			if(valid(L[u]) && valid(L[v]))
				path.emplace_back(v, u);
		}
		R[u] = 1+dfsTimer;
	}

	long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
		for(int i = 0; i < M; ++i) {
			g[A[i]].push_back(B[i]);
			g[B[i]].push_back(A[i]);
		}
		init(0);
		r = P;
		while(R[r] - L[r] < 60)	V = Move(r = p[r]);

		dfs(dfsTimer = 0);

		long long x {};
		set<int> done;

		done.insert(L[r] % 60);
		if(V) x |= 1LL << (L[r] % 60);

		while(size(done) < 60) {
			auto [v, pos] = path.back();
			path.pop_back();

			done.insert(pos = L[v] % 60);
			if(Move(r = v))
				x |= 1LL << pos;
		}
		return x;
	}
};

long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
	return IOI::Ioi(N, M, A, B, P, V, T);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1516 KB Output is correct
2 Correct 2 ms 1516 KB Output is correct
3 Correct 2 ms 1648 KB Output is correct
4 Correct 2 ms 1576 KB Output is correct
5 Correct 2 ms 1576 KB Output is correct
6 Correct 2 ms 1580 KB Output is correct
7 Correct 2 ms 1788 KB Output is correct
8 Correct 2 ms 1788 KB Output is correct
9 Correct 2 ms 1580 KB Output is correct
10 Correct 2 ms 1536 KB Output is correct
11 Correct 6 ms 1964 KB Output is correct
12 Correct 2 ms 1524 KB Output is correct
13 Correct 2 ms 1648 KB Output is correct
14 Correct 2 ms 1644 KB Output is correct
15 Correct 2 ms 1660 KB Output is correct
16 Correct 2 ms 1656 KB Output is correct
17 Correct 2 ms 1788 KB Output is correct
18 Correct 2 ms 1656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 5676 KB Output is correct
2 Correct 31 ms 5792 KB Output is correct
3 Correct 24 ms 5660 KB Output is correct
4 Correct 15 ms 3864 KB Output is correct
5 Correct 15 ms 4756 KB Output is correct
6 Correct 15 ms 4348 KB Output is correct
7 Correct 19 ms 4464 KB Output is correct
8 Correct 19 ms 4548 KB Output is correct
9 Correct 15 ms 4500 KB Output is correct
10 Correct 12 ms 3868 KB Output is correct
11 Correct 13 ms 3724 KB Output is correct
12 Correct 16 ms 3576 KB Output is correct
13 Correct 16 ms 3520 KB Output is correct
14 Correct 19 ms 3796 KB Output is correct
15 Correct 22 ms 4020 KB Output is correct
16 Correct 17 ms 3996 KB Output is correct
17 Correct 15 ms 3852 KB Output is correct
18 Correct 14 ms 3812 KB Output is correct
19 Correct 19 ms 3868 KB Output is correct
20 Correct 12 ms 4460 KB Output is correct
21 Correct 12 ms 4424 KB Output is correct
22 Correct 17 ms 4180 KB Output is correct
23 Correct 20 ms 4492 KB Output is correct
24 Correct 16 ms 4228 KB Output is correct
25 Correct 16 ms 4248 KB Output is correct
26 Correct 15 ms 4464 KB Output is correct
27 Correct 16 ms 4488 KB Output is correct
28 Correct 19 ms 4444 KB Output is correct
29 Correct 13 ms 4216 KB Output is correct
30 Correct 15 ms 4152 KB Output is correct
31 Correct 2 ms 1528 KB Output is correct
32 Correct 2 ms 1572 KB Output is correct
33 Correct 2 ms 1788 KB Output is correct
34 Correct 2 ms 1524 KB Output is correct
35 Correct 2 ms 1524 KB Output is correct
36 Correct 2 ms 1516 KB Output is correct
37 Correct 2 ms 1516 KB Output is correct
38 Correct 2 ms 1516 KB Output is correct
39 Correct 2 ms 1604 KB Output is correct
40 Correct 2 ms 1512 KB Output is correct
41 Correct 2 ms 1520 KB Output is correct
42 Correct 2 ms 1640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1524 KB Output is correct
2 Correct 2 ms 1576 KB Output is correct
3 Correct 2 ms 1572 KB Output is correct
4 Correct 3 ms 2336 KB Output is correct
5 Correct 3 ms 2336 KB Output is correct
6 Correct 4 ms 2328 KB Output is correct
7 Correct 4 ms 2300 KB Output is correct
8 Correct 4 ms 2320 KB Output is correct
9 Correct 17 ms 5600 KB Output is correct
10 Correct 13 ms 5640 KB Output is correct
11 Correct 17 ms 5656 KB Output is correct
12 Correct 2 ms 1528 KB Output is correct
13 Correct 2 ms 1516 KB Output is correct
14 Correct 2 ms 1520 KB Output is correct
15 Correct 2 ms 1516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 5672 KB Output is correct
2 Correct 28 ms 5600 KB Output is correct
3 Correct 28 ms 5616 KB Output is correct
4 Correct 18 ms 3856 KB Output is correct
5 Correct 16 ms 5128 KB Output is correct
6 Correct 15 ms 4488 KB Output is correct
7 Correct 15 ms 4520 KB Output is correct
8 Correct 15 ms 4244 KB Output is correct
9 Correct 15 ms 4248 KB Output is correct
10 Correct 14 ms 3856 KB Output is correct
11 Correct 14 ms 3852 KB Output is correct
12 Correct 15 ms 3520 KB Output is correct
13 Correct 13 ms 3556 KB Output is correct
14 Correct 13 ms 3724 KB Output is correct
15 Correct 14 ms 4048 KB Output is correct
16 Correct 15 ms 4096 KB Output is correct
17 Correct 15 ms 3820 KB Output is correct
18 Correct 16 ms 3848 KB Output is correct
19 Correct 15 ms 3852 KB Output is correct
20 Correct 12 ms 4496 KB Output is correct
21 Correct 14 ms 4480 KB Output is correct
22 Correct 17 ms 4316 KB Output is correct
23 Correct 15 ms 4212 KB Output is correct
24 Correct 14 ms 4236 KB Output is correct
25 Correct 15 ms 4492 KB Output is correct
26 Correct 14 ms 4480 KB Output is correct
27 Correct 15 ms 4476 KB Output is correct
28 Correct 14 ms 4116 KB Output is correct
29 Correct 13 ms 4164 KB Output is correct
30 Correct 16 ms 4284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 5720 KB Output is correct
2 Correct 27 ms 5664 KB Output is correct
3 Correct 27 ms 5708 KB Output is correct
4 Correct 15 ms 3848 KB Output is correct
5 Correct 15 ms 5372 KB Output is correct
6 Correct 15 ms 4344 KB Output is correct
7 Correct 15 ms 4304 KB Output is correct
8 Correct 15 ms 4440 KB Output is correct
9 Correct 19 ms 4476 KB Output is correct
10 Correct 17 ms 3724 KB Output is correct
11 Correct 13 ms 3836 KB Output is correct
12 Correct 15 ms 3596 KB Output is correct
13 Correct 13 ms 3576 KB Output is correct
14 Correct 14 ms 3792 KB Output is correct
15 Correct 15 ms 4016 KB Output is correct
16 Correct 14 ms 4104 KB Output is correct
17 Correct 14 ms 3836 KB Output is correct
18 Correct 15 ms 3836 KB Output is correct
19 Correct 19 ms 3728 KB Output is correct
20 Correct 13 ms 4440 KB Output is correct
21 Correct 12 ms 4452 KB Output is correct
22 Correct 15 ms 4232 KB Output is correct
23 Correct 15 ms 4224 KB Output is correct
24 Correct 15 ms 4316 KB Output is correct
25 Correct 15 ms 4292 KB Output is correct
26 Correct 14 ms 4240 KB Output is correct
27 Correct 19 ms 4500 KB Output is correct
28 Correct 17 ms 4452 KB Output is correct
29 Correct 16 ms 4216 KB Output is correct
30 Correct 14 ms 4256 KB Output is correct
31 Correct 2 ms 1524 KB Output is correct
32 Correct 2 ms 1516 KB Output is correct
33 Correct 2 ms 1588 KB Output is correct
34 Correct 2 ms 1516 KB Output is correct
35 Correct 2 ms 1524 KB Output is correct
36 Correct 2 ms 1572 KB Output is correct
37 Correct 2 ms 1580 KB Output is correct
38 Correct 2 ms 1572 KB Output is correct
39 Correct 1 ms 1520 KB Output is correct
40 Correct 2 ms 1520 KB Output is correct
41 Correct 2 ms 1528 KB Output is correct
42 Correct 2 ms 1516 KB Output is correct