Submission #707969

# Submission time Handle Problem Language Result Execution time Memory
707969 2023-03-10T15:35:40 Z 600Mihnea Game (APIO22_game) C++17
100 / 100
1099 ms 69680 KB
#include "game.h"
#include <cmath>
#include <functional>
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <cassert>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>
#include <numeric>

using namespace std;

const int INF = (int)1e9 + 7;
int n;
int k;
vector<vector<int>> g, ig;
vector<pair<int, int>> range;

void init(int nn, int kk)
{
	n = nn;
	k = kk;
	g.clear();
	ig.clear();
	range.clear();
	g.resize(n + 1);
	ig.resize(n + 1);
	range.resize(n + 1);
	for (int i = 1; i <= k; i++)
	{
		range[i] = { i, i };
	}
	for (int i = k + 1; i <= n; i++)
	{
		range[i] = { 0, k + 1 };
	}
}

int upd(int from, int to)
{
	if (range[from].first >= range[to].second) return 1;
	if (range[from].second <= range[to].first) return 0;


	while (range[from].first >= (range[to].first + range[to].second) / 2 + 1)
	{
		range[to].first = (range[to].first + range[to].second) / 2 + 1;
		for (auto& vertex : g[to])
		{
			if (upd(to, vertex))
			{
				return 1;
			}
		}
	}

	while (range[to].second <= (range[from].second + range[from].first) / 2)
	{
		range[from].second = (range[from].second + range[from].first) / 2;
		for (auto& vertex : ig[from])
		{
			if (upd(vertex, from))
			{
				return 1;
			}
		}
	}

	return 0;
}

int add_teleporter(int from, int to)
{
	from++;
	to++;
	assert(1 <= from && from <= n);
	assert(1 <= to && to <= n);

	g[from].push_back(to);
	ig[to].push_back(from);

	if (from >= to && from <= k) return 1;
	if (from == to) return 0;

	return upd(from, to);
}
# 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 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 1 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 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 1 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 0 ms 208 KB Output is correct
11 Correct 0 ms 208 KB Output is correct
12 Correct 1 ms 276 KB Output is correct
13 Correct 0 ms 208 KB Output is correct
14 Correct 0 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 0 ms 208 KB Output is correct
19 Correct 1 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 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 1 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 0 ms 208 KB Output is correct
11 Correct 0 ms 208 KB Output is correct
12 Correct 1 ms 276 KB Output is correct
13 Correct 0 ms 208 KB Output is correct
14 Correct 0 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 0 ms 208 KB Output is correct
19 Correct 1 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 464 KB Output is correct
25 Correct 3 ms 388 KB Output is correct
26 Correct 2 ms 336 KB Output is correct
27 Correct 2 ms 336 KB Output is correct
28 Correct 2 ms 464 KB Output is correct
29 Correct 3 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 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 1 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 0 ms 208 KB Output is correct
11 Correct 0 ms 208 KB Output is correct
12 Correct 1 ms 276 KB Output is correct
13 Correct 0 ms 208 KB Output is correct
14 Correct 0 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 0 ms 208 KB Output is correct
19 Correct 1 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 464 KB Output is correct
25 Correct 3 ms 388 KB Output is correct
26 Correct 2 ms 336 KB Output is correct
27 Correct 2 ms 336 KB Output is correct
28 Correct 2 ms 464 KB Output is correct
29 Correct 3 ms 464 KB Output is correct
30 Correct 17 ms 3024 KB Output is correct
31 Correct 5 ms 2352 KB Output is correct
32 Correct 30 ms 6020 KB Output is correct
33 Correct 15 ms 3832 KB Output is correct
34 Correct 35 ms 8252 KB Output is correct
35 Correct 29 ms 5300 KB Output is correct
36 Correct 32 ms 3840 KB Output is correct
37 Correct 33 ms 3816 KB Output is correct
38 Correct 25 ms 3524 KB Output is correct
39 Correct 27 ms 3604 KB Output is correct
40 Correct 33 ms 8072 KB Output is correct
41 Correct 30 ms 4732 KB Output is correct
42 Correct 29 ms 4380 KB Output is correct
43 Correct 34 ms 5016 KB Output is correct
44 Correct 34 ms 4888 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 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 1 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 0 ms 208 KB Output is correct
11 Correct 0 ms 208 KB Output is correct
12 Correct 1 ms 276 KB Output is correct
13 Correct 0 ms 208 KB Output is correct
14 Correct 0 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 0 ms 208 KB Output is correct
19 Correct 1 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 464 KB Output is correct
25 Correct 3 ms 388 KB Output is correct
26 Correct 2 ms 336 KB Output is correct
27 Correct 2 ms 336 KB Output is correct
28 Correct 2 ms 464 KB Output is correct
29 Correct 3 ms 464 KB Output is correct
30 Correct 17 ms 3024 KB Output is correct
31 Correct 5 ms 2352 KB Output is correct
32 Correct 30 ms 6020 KB Output is correct
33 Correct 15 ms 3832 KB Output is correct
34 Correct 35 ms 8252 KB Output is correct
35 Correct 29 ms 5300 KB Output is correct
36 Correct 32 ms 3840 KB Output is correct
37 Correct 33 ms 3816 KB Output is correct
38 Correct 25 ms 3524 KB Output is correct
39 Correct 27 ms 3604 KB Output is correct
40 Correct 33 ms 8072 KB Output is correct
41 Correct 30 ms 4732 KB Output is correct
42 Correct 29 ms 4380 KB Output is correct
43 Correct 34 ms 5016 KB Output is correct
44 Correct 34 ms 4888 KB Output is correct
45 Correct 254 ms 28048 KB Output is correct
46 Correct 14 ms 17096 KB Output is correct
47 Correct 13 ms 17004 KB Output is correct
48 Correct 316 ms 45560 KB Output is correct
49 Correct 245 ms 35548 KB Output is correct
50 Correct 645 ms 54968 KB Output is correct
51 Correct 763 ms 46684 KB Output is correct
52 Correct 590 ms 35572 KB Output is correct
53 Correct 696 ms 35676 KB Output is correct
54 Correct 727 ms 35556 KB Output is correct
55 Correct 883 ms 35840 KB Output is correct
56 Correct 1027 ms 35576 KB Output is correct
57 Correct 440 ms 29468 KB Output is correct
58 Correct 470 ms 29592 KB Output is correct
59 Correct 496 ms 29692 KB Output is correct
60 Correct 508 ms 29628 KB Output is correct
61 Correct 599 ms 29368 KB Output is correct
62 Correct 466 ms 41872 KB Output is correct
63 Correct 372 ms 38460 KB Output is correct
64 Correct 1020 ms 69680 KB Output is correct
65 Correct 465 ms 37256 KB Output is correct
66 Correct 373 ms 33364 KB Output is correct
67 Correct 755 ms 42848 KB Output is correct
68 Correct 183 ms 26368 KB Output is correct
69 Correct 58 ms 20168 KB Output is correct
70 Correct 695 ms 42504 KB Output is correct
71 Correct 329 ms 29292 KB Output is correct
72 Correct 219 ms 24860 KB Output is correct
73 Correct 635 ms 39324 KB Output is correct
74 Correct 1099 ms 35484 KB Output is correct
75 Correct 1000 ms 47300 KB Output is correct
76 Correct 1043 ms 54224 KB Output is correct