Submission #578731

# Submission time Handle Problem Language Result Execution time Memory
578731 2022-06-17T19:14:50 Z Noam527 Game (APIO22_game) C++17
100 / 100
1479 ms 69632 KB
#include <bits/stdc++.h>
#include "game.h"
const int OO = 0;
const int OOO = 0;
using namespace std;

int n, k;
vector<vector<int>> g, grev;
vector<int> s, e;
// s: maximum that reaches us
// e: minimum that we can reach
// s <= e as long as the answer is 0 (with s < e for all non-special vertices)

void init(int nn, int kk) {
	g.clear();
	grev.clear();
	s.clear();
	e.clear();

	n = nn;
	k = kk;
	g.resize(n);
	grev.resize(n);
	s.resize(n, -1);
	e.resize(n, k);

	for (int i = 0; i < k; i++) {
		s[i] = i;
		e[i] = i;
	}
}

int add(int u, int v) {
	if (OO) {
		cout << "add " << u << " " << v << '\n';
	}
	if (s[u] >= e[v]) return 1;
	if (s[u] > s[v]) {
		while (s[u] - s[v] >= e[v] - s[u]) {
			if (OO) {
				cout << "add " << u << " " << v << " updates forward\n";
			}
			s[v] = (s[v] + e[v] + 1) / 2;
			for (const auto &i : g[v])
				if (add(v, i)) return 1;
		}
	}
	if (e[u] > e[v]) {
		while (e[u] - e[v] >= e[v] - s[u]) {
			if (OO) {
				cout << "add " << u << " " << v << " updates backward\n";
			}
			e[u] = (s[u] + e[u]) / 2;
			for (const auto &i : grev[u])
				if (add(i, u)) return 1;
		}
	}
	return 0;
}

void brute_dfs(vector<int> &vis, int v) {
	if (vis[v]) return;
	vis[v] = 1;
	for (const auto &i : g[v])
		brute_dfs(vis, i);
}

int brute() {
	vector<int> vis(n);
	for (int i = 0; i < k; i++) {
		for (auto &x : vis) x = 0;
		for (const auto &j : g[i])
			brute_dfs(vis, j);
		for (int j = 0; j <= i; j++)
			if (vis[j]) return 1;
	}
	return 0;
}

int add_teleporter(int u, int v) {
	if (OO) {
		cout << "current s: ";
		for (const auto &i : s) cout << i << " "; cout << '\n';
		cout << "current e: ";
		for (const auto &i : e) cout << i << " "; cout << '\n';
	}
	
	if (u < k && v < k) {
		return u >= v;
	}
	
	g[u].push_back(v);
	grev[v].push_back(u);
	int x = add(u, v);
	if (OOO) {
		int y = brute();
		if (x != y) {
			cout << "difference! " << x << " " << y << '\n';
			return 2;
		}
	}
	return x;
}

Compilation message

game.cpp: In function 'int add_teleporter(int, int)':
game.cpp:83:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   83 |   for (const auto &i : s) cout << i << " "; cout << '\n';
      |   ^~~
game.cpp:83:45: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   83 |   for (const auto &i : s) cout << i << " "; cout << '\n';
      |                                             ^~~~
game.cpp:85:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   85 |   for (const auto &i : e) cout << i << " "; cout << '\n';
      |   ^~~
game.cpp:85:45: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   85 |   for (const auto &i : e) cout << i << " "; cout << '\n';
      |                                             ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 1 ms 208 KB Output is correct
17 Correct 1 ms 208 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 0 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 1 ms 208 KB Output is correct
17 Correct 1 ms 208 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 0 ms 208 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 0 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 396 KB Output is correct
25 Correct 3 ms 464 KB Output is correct
26 Correct 3 ms 336 KB Output is correct
27 Correct 4 ms 336 KB Output is correct
28 Correct 2 ms 464 KB Output is correct
29 Correct 2 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 1 ms 208 KB Output is correct
17 Correct 1 ms 208 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 0 ms 208 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 0 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 396 KB Output is correct
25 Correct 3 ms 464 KB Output is correct
26 Correct 3 ms 336 KB Output is correct
27 Correct 4 ms 336 KB Output is correct
28 Correct 2 ms 464 KB Output is correct
29 Correct 2 ms 464 KB Output is correct
30 Correct 20 ms 3196 KB Output is correct
31 Correct 6 ms 2256 KB Output is correct
32 Correct 24 ms 6088 KB Output is correct
33 Correct 16 ms 3736 KB Output is correct
34 Correct 32 ms 8264 KB Output is correct
35 Correct 35 ms 5288 KB Output is correct
36 Correct 34 ms 3836 KB Output is correct
37 Correct 31 ms 3788 KB Output is correct
38 Correct 32 ms 3560 KB Output is correct
39 Correct 31 ms 3632 KB Output is correct
40 Correct 43 ms 8024 KB Output is correct
41 Correct 30 ms 4808 KB Output is correct
42 Correct 32 ms 4256 KB Output is correct
43 Correct 45 ms 5140 KB Output is correct
44 Correct 41 ms 5020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 1 ms 208 KB Output is correct
17 Correct 1 ms 208 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 0 ms 208 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 0 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 396 KB Output is correct
25 Correct 3 ms 464 KB Output is correct
26 Correct 3 ms 336 KB Output is correct
27 Correct 4 ms 336 KB Output is correct
28 Correct 2 ms 464 KB Output is correct
29 Correct 2 ms 464 KB Output is correct
30 Correct 20 ms 3196 KB Output is correct
31 Correct 6 ms 2256 KB Output is correct
32 Correct 24 ms 6088 KB Output is correct
33 Correct 16 ms 3736 KB Output is correct
34 Correct 32 ms 8264 KB Output is correct
35 Correct 35 ms 5288 KB Output is correct
36 Correct 34 ms 3836 KB Output is correct
37 Correct 31 ms 3788 KB Output is correct
38 Correct 32 ms 3560 KB Output is correct
39 Correct 31 ms 3632 KB Output is correct
40 Correct 43 ms 8024 KB Output is correct
41 Correct 30 ms 4808 KB Output is correct
42 Correct 32 ms 4256 KB Output is correct
43 Correct 45 ms 5140 KB Output is correct
44 Correct 41 ms 5020 KB Output is correct
45 Correct 304 ms 28072 KB Output is correct
46 Correct 17 ms 17168 KB Output is correct
47 Correct 14 ms 17008 KB Output is correct
48 Correct 378 ms 45708 KB Output is correct
49 Correct 314 ms 35500 KB Output is correct
50 Correct 740 ms 55044 KB Output is correct
51 Correct 964 ms 46752 KB Output is correct
52 Correct 558 ms 35580 KB Output is correct
53 Correct 839 ms 35892 KB Output is correct
54 Correct 925 ms 35644 KB Output is correct
55 Correct 1041 ms 36148 KB Output is correct
56 Correct 1307 ms 35920 KB Output is correct
57 Correct 534 ms 29496 KB Output is correct
58 Correct 555 ms 29648 KB Output is correct
59 Correct 585 ms 29844 KB Output is correct
60 Correct 546 ms 29488 KB Output is correct
61 Correct 653 ms 29496 KB Output is correct
62 Correct 510 ms 41836 KB Output is correct
63 Correct 401 ms 38512 KB Output is correct
64 Correct 1202 ms 69632 KB Output is correct
65 Correct 552 ms 37384 KB Output is correct
66 Correct 492 ms 33268 KB Output is correct
67 Correct 958 ms 42780 KB Output is correct
68 Correct 226 ms 26324 KB Output is correct
69 Correct 62 ms 20200 KB Output is correct
70 Correct 738 ms 42456 KB Output is correct
71 Correct 339 ms 28320 KB Output is correct
72 Correct 239 ms 24244 KB Output is correct
73 Correct 830 ms 41756 KB Output is correct
74 Correct 1479 ms 35680 KB Output is correct
75 Correct 1324 ms 47452 KB Output is correct
76 Correct 1223 ms 53064 KB Output is correct