답안 #572808

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
572808 2022-06-05T10:20:12 Z 8e7 게임 (APIO22_game) C++17
100 / 100
2676 ms 71840 KB
//Challenge: Accepted
//#define _GLIBCXX_DEBUG 1
#include "game.h"
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r) {
	while (l != r) cout << *l << " ", l++;
	cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 300005
#define mod 998244353
#define pii pair<int, int>
#define ff first
#define ss second
const int inf = 1e9;
int in[maxn], out[maxn];
int block[maxn];
vector<int> adj[maxn], rev[maxn];
int N, K;
void init(int n, int k) {
	N = n, K = k;
	for (int i = 0;i < n;i++) {
		in[i] = inf, out[i] = -inf;
		block[i] = 19;
	}
	for (int i = 0;i < k - 1;i++) {
		adj[i].push_back(i + 1);
	}
	for (int i = 0;i < k;i++) {
		in[i] = i, out[i] = i;
		block[i] = 0;
	}
}
bool dfs(int n, int d, int type, vector<int> &add) {
	bool ret = 0;
	if (n >= K && in[n] <= out[n]) return 1;
	if (in[n] / (1<<d) == out[n] / (1<<d) && block[n] > d) {
		block[n] = d;
		add.push_back(n);
	}
	if (type == 0) {
		for (int i:adj[n]) {
			if (block[i] <= d+1 && out[i] / (1<<d) < out[n] / (1<<d)) {
				out[i] = out[n];
				ret |= dfs(i, d, type, add);
			}
		}
	} else {
		for (int i:rev[n]) {
			if (block[i] <= d+1 && in[i] / (1<<d) > in[n] / (1<<d)) {
				in[i] = in[n];
				ret |= dfs(i, d, type, add);
			}
		}
	}
	return ret;
}
bool solve(int u, int v, int d, vector<int> check) {
	if (d < 0) return 0;
	if (block[v] <= d && out[v] / (1<<(d-1)) < out[u] / (1<<(d-1))) {
		check.push_back(v);
	}
	if (block[u] <= d && in[u] / (1<<(d-1)) > in[v] / (1<<(d-1))) {
		check.push_back(u);
	}
	vector<int> rec;
	for (int i:check) {
		for (int j:adj[i]) in[i] = min(in[i], in[j]);
		for (int j:rev[i]) out[i] = max(out[i], out[j]);
		if (dfs(i, d-1, 0, rec) || dfs(i, d-1, 1, rec)) return 1;
	}
	return solve(u, v, d-1, rec);
}
int add_teleporter(int u, int v) {
	if (u < K && v < K) {
		if (u >= v) return 1;
	}
	adj[u].push_back(v);
	rev[v].push_back(u);
	vector<int> tmp;
	int val = solve(u, v, 19, tmp);
	return val;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14416 KB Output is correct
2 Correct 8 ms 14288 KB Output is correct
3 Correct 8 ms 14416 KB Output is correct
4 Correct 8 ms 14416 KB Output is correct
5 Correct 9 ms 14416 KB Output is correct
6 Correct 9 ms 14416 KB Output is correct
7 Correct 8 ms 14416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14416 KB Output is correct
2 Correct 8 ms 14288 KB Output is correct
3 Correct 8 ms 14416 KB Output is correct
4 Correct 8 ms 14416 KB Output is correct
5 Correct 9 ms 14416 KB Output is correct
6 Correct 9 ms 14416 KB Output is correct
7 Correct 8 ms 14416 KB Output is correct
8 Correct 8 ms 14288 KB Output is correct
9 Correct 10 ms 14288 KB Output is correct
10 Correct 10 ms 14288 KB Output is correct
11 Correct 8 ms 14288 KB Output is correct
12 Correct 9 ms 14416 KB Output is correct
13 Correct 8 ms 14416 KB Output is correct
14 Correct 10 ms 14372 KB Output is correct
15 Correct 8 ms 14416 KB Output is correct
16 Correct 9 ms 14392 KB Output is correct
17 Correct 8 ms 14332 KB Output is correct
18 Correct 9 ms 14308 KB Output is correct
19 Correct 11 ms 14416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14416 KB Output is correct
2 Correct 8 ms 14288 KB Output is correct
3 Correct 8 ms 14416 KB Output is correct
4 Correct 8 ms 14416 KB Output is correct
5 Correct 9 ms 14416 KB Output is correct
6 Correct 9 ms 14416 KB Output is correct
7 Correct 8 ms 14416 KB Output is correct
8 Correct 8 ms 14288 KB Output is correct
9 Correct 10 ms 14288 KB Output is correct
10 Correct 10 ms 14288 KB Output is correct
11 Correct 8 ms 14288 KB Output is correct
12 Correct 9 ms 14416 KB Output is correct
13 Correct 8 ms 14416 KB Output is correct
14 Correct 10 ms 14372 KB Output is correct
15 Correct 8 ms 14416 KB Output is correct
16 Correct 9 ms 14392 KB Output is correct
17 Correct 8 ms 14332 KB Output is correct
18 Correct 9 ms 14308 KB Output is correct
19 Correct 11 ms 14416 KB Output is correct
20 Correct 10 ms 14472 KB Output is correct
21 Correct 8 ms 14452 KB Output is correct
22 Correct 9 ms 14444 KB Output is correct
23 Correct 9 ms 14416 KB Output is correct
24 Correct 10 ms 14544 KB Output is correct
25 Correct 11 ms 14540 KB Output is correct
26 Correct 13 ms 14428 KB Output is correct
27 Correct 11 ms 14444 KB Output is correct
28 Correct 10 ms 14416 KB Output is correct
29 Correct 14 ms 14592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14416 KB Output is correct
2 Correct 8 ms 14288 KB Output is correct
3 Correct 8 ms 14416 KB Output is correct
4 Correct 8 ms 14416 KB Output is correct
5 Correct 9 ms 14416 KB Output is correct
6 Correct 9 ms 14416 KB Output is correct
7 Correct 8 ms 14416 KB Output is correct
8 Correct 8 ms 14288 KB Output is correct
9 Correct 10 ms 14288 KB Output is correct
10 Correct 10 ms 14288 KB Output is correct
11 Correct 8 ms 14288 KB Output is correct
12 Correct 9 ms 14416 KB Output is correct
13 Correct 8 ms 14416 KB Output is correct
14 Correct 10 ms 14372 KB Output is correct
15 Correct 8 ms 14416 KB Output is correct
16 Correct 9 ms 14392 KB Output is correct
17 Correct 8 ms 14332 KB Output is correct
18 Correct 9 ms 14308 KB Output is correct
19 Correct 11 ms 14416 KB Output is correct
20 Correct 10 ms 14472 KB Output is correct
21 Correct 8 ms 14452 KB Output is correct
22 Correct 9 ms 14444 KB Output is correct
23 Correct 9 ms 14416 KB Output is correct
24 Correct 10 ms 14544 KB Output is correct
25 Correct 11 ms 14540 KB Output is correct
26 Correct 13 ms 14428 KB Output is correct
27 Correct 11 ms 14444 KB Output is correct
28 Correct 10 ms 14416 KB Output is correct
29 Correct 14 ms 14592 KB Output is correct
30 Correct 34 ms 15784 KB Output is correct
31 Correct 13 ms 15184 KB Output is correct
32 Correct 35 ms 17080 KB Output is correct
33 Correct 34 ms 16628 KB Output is correct
34 Correct 74 ms 21476 KB Output is correct
35 Correct 80 ms 18248 KB Output is correct
36 Correct 90 ms 16900 KB Output is correct
37 Correct 92 ms 16876 KB Output is correct
38 Correct 66 ms 16412 KB Output is correct
39 Correct 76 ms 16428 KB Output is correct
40 Correct 88 ms 21072 KB Output is correct
41 Correct 58 ms 17716 KB Output is correct
42 Correct 72 ms 16876 KB Output is correct
43 Correct 87 ms 18472 KB Output is correct
44 Correct 99 ms 21040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14416 KB Output is correct
2 Correct 8 ms 14288 KB Output is correct
3 Correct 8 ms 14416 KB Output is correct
4 Correct 8 ms 14416 KB Output is correct
5 Correct 9 ms 14416 KB Output is correct
6 Correct 9 ms 14416 KB Output is correct
7 Correct 8 ms 14416 KB Output is correct
8 Correct 8 ms 14288 KB Output is correct
9 Correct 10 ms 14288 KB Output is correct
10 Correct 10 ms 14288 KB Output is correct
11 Correct 8 ms 14288 KB Output is correct
12 Correct 9 ms 14416 KB Output is correct
13 Correct 8 ms 14416 KB Output is correct
14 Correct 10 ms 14372 KB Output is correct
15 Correct 8 ms 14416 KB Output is correct
16 Correct 9 ms 14392 KB Output is correct
17 Correct 8 ms 14332 KB Output is correct
18 Correct 9 ms 14308 KB Output is correct
19 Correct 11 ms 14416 KB Output is correct
20 Correct 10 ms 14472 KB Output is correct
21 Correct 8 ms 14452 KB Output is correct
22 Correct 9 ms 14444 KB Output is correct
23 Correct 9 ms 14416 KB Output is correct
24 Correct 10 ms 14544 KB Output is correct
25 Correct 11 ms 14540 KB Output is correct
26 Correct 13 ms 14428 KB Output is correct
27 Correct 11 ms 14444 KB Output is correct
28 Correct 10 ms 14416 KB Output is correct
29 Correct 14 ms 14592 KB Output is correct
30 Correct 34 ms 15784 KB Output is correct
31 Correct 13 ms 15184 KB Output is correct
32 Correct 35 ms 17080 KB Output is correct
33 Correct 34 ms 16628 KB Output is correct
34 Correct 74 ms 21476 KB Output is correct
35 Correct 80 ms 18248 KB Output is correct
36 Correct 90 ms 16900 KB Output is correct
37 Correct 92 ms 16876 KB Output is correct
38 Correct 66 ms 16412 KB Output is correct
39 Correct 76 ms 16428 KB Output is correct
40 Correct 88 ms 21072 KB Output is correct
41 Correct 58 ms 17716 KB Output is correct
42 Correct 72 ms 16876 KB Output is correct
43 Correct 87 ms 18472 KB Output is correct
44 Correct 99 ms 21040 KB Output is correct
45 Correct 318 ms 29176 KB Output is correct
46 Correct 22 ms 18256 KB Output is correct
47 Correct 19 ms 18332 KB Output is correct
48 Correct 432 ms 48660 KB Output is correct
49 Correct 353 ms 36688 KB Output is correct
50 Correct 1469 ms 58408 KB Output is correct
51 Correct 1306 ms 46032 KB Output is correct
52 Correct 1239 ms 37808 KB Output is correct
53 Correct 1404 ms 38544 KB Output is correct
54 Correct 1421 ms 37356 KB Output is correct
55 Correct 2559 ms 49528 KB Output is correct
56 Correct 2441 ms 45664 KB Output is correct
57 Correct 813 ms 42948 KB Output is correct
58 Correct 821 ms 34116 KB Output is correct
59 Correct 838 ms 40836 KB Output is correct
60 Correct 922 ms 38036 KB Output is correct
61 Correct 1077 ms 36576 KB Output is correct
62 Correct 945 ms 42500 KB Output is correct
63 Correct 771 ms 37700 KB Output is correct
64 Correct 2297 ms 63284 KB Output is correct
65 Correct 803 ms 37572 KB Output is correct
66 Correct 627 ms 33160 KB Output is correct
67 Correct 1116 ms 42960 KB Output is correct
68 Correct 253 ms 28976 KB Output is correct
69 Correct 75 ms 22892 KB Output is correct
70 Correct 1155 ms 43624 KB Output is correct
71 Correct 450 ms 30408 KB Output is correct
72 Correct 327 ms 26420 KB Output is correct
73 Correct 877 ms 38344 KB Output is correct
74 Correct 2676 ms 46264 KB Output is correct
75 Correct 1902 ms 53000 KB Output is correct
76 Correct 2282 ms 71840 KB Output is correct