Submission #725411

# Submission time Handle Problem Language Result Execution time Memory
725411 2023-04-17T11:31:04 Z SanguineChameleon Game (APIO22_game) C++17
30 / 100
222 ms 18704 KB
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma")

#include "game.h"
#include <bits/stdc++.h>
using namespace std;

const int shift = 9;
const int maxN = 3e5 + 20;
int max_in[maxN];
int min_out[maxN];
vector<int> adj1[maxN];
vector<int> adj2[maxN];
bool done = false;
int n, k;

void init(int _n, int _k) {
	n = _n;
	k = _k;
	for (int i = 0; i < k; i++) {
		max_in[i] = i;
		min_out[i] = i + 1;
	}
	for (int i = k; i < n; i++) {
		max_in[i] = 0;
		min_out[i] = k + 1;
	}
}

void update_in(int u, int val);

void update_out(int u, int val);

void update_in(int u, int val) {
	if (done) {
		return;
	}
	bool diff = (max_in[u] >> shift) != (val >> shift);
	bool same = (max_in[u] >> shift) == (min_out[u] >> shift);
	max_in[u] = val;
	if (max_in[u] >= min_out[u]) {
		done = true;
		return;
	}
	if (diff) {
		for (auto v: adj1[u]) {
			if (max_in[u] > max_in[v]) {
				update_in(v, max_in[u]);
			}
		}
	}
	else if (same) {
		for (auto v: adj1[u]) {
			if (max_in[u] > max_in[v]) {
				update_in(v, max_in[u]);
			}
		}
		for (auto v: adj2[u]) {
			if (min_out[u] < min_out[v]) {
				update_out(v, min_out[u]);
			}
		}
	}
}
 
void update_out(int u, int val) {
	if (done) {
		return;
	}
	bool diff = (min_out[u] >> shift) != (val >> shift);
	bool same = (max_in[u] >> shift) == (min_out[u] >> shift);
	min_out[u] = val;
	if (max_in[u] >= min_out[u]) {
		done = true;
		return;
	}
	if (diff) {
		for (auto v: adj2[u]) {
			update_out(v, min_out[u]);
		}
	}
	else if (same) {
		for (auto v: adj1[u]) {
			if (max_in[u] > max_in[v]) {
				update_in(v, max_in[u]);
			}
		}
		for (auto v: adj2[u]) {
			if (min_out[u] < min_out[v]) {
				update_out(v, min_out[u]);
			}
		}
	}
}
 
int add_teleporter(int u, int v) {
	int val = max(max_in[u], (u < k ? u + 1 : 0));
	if (val > max_in[v]) {
		update_in(v, val);
	}
	if (min_out[v] < min_out[u]) {
		update_out(u, min_out[v]);
	}
	adj1[u].push_back(v);
	adj2[v].push_back(u);
	return done;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14288 KB Output is correct
2 Correct 9 ms 14356 KB Output is correct
3 Correct 8 ms 14288 KB Output is correct
4 Correct 8 ms 14288 KB Output is correct
5 Correct 8 ms 14404 KB Output is correct
6 Correct 8 ms 14340 KB Output is correct
7 Correct 9 ms 14288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14288 KB Output is correct
2 Correct 9 ms 14356 KB Output is correct
3 Correct 8 ms 14288 KB Output is correct
4 Correct 8 ms 14288 KB Output is correct
5 Correct 8 ms 14404 KB Output is correct
6 Correct 8 ms 14340 KB Output is correct
7 Correct 9 ms 14288 KB Output is correct
8 Correct 8 ms 14388 KB Output is correct
9 Correct 8 ms 14288 KB Output is correct
10 Correct 9 ms 14288 KB Output is correct
11 Correct 8 ms 14288 KB Output is correct
12 Correct 10 ms 14288 KB Output is correct
13 Correct 9 ms 14352 KB Output is correct
14 Correct 10 ms 14288 KB Output is correct
15 Correct 9 ms 14288 KB Output is correct
16 Correct 9 ms 14288 KB Output is correct
17 Correct 9 ms 14288 KB Output is correct
18 Correct 9 ms 14288 KB Output is correct
19 Correct 9 ms 14288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14288 KB Output is correct
2 Correct 9 ms 14356 KB Output is correct
3 Correct 8 ms 14288 KB Output is correct
4 Correct 8 ms 14288 KB Output is correct
5 Correct 8 ms 14404 KB Output is correct
6 Correct 8 ms 14340 KB Output is correct
7 Correct 9 ms 14288 KB Output is correct
8 Correct 8 ms 14388 KB Output is correct
9 Correct 8 ms 14288 KB Output is correct
10 Correct 9 ms 14288 KB Output is correct
11 Correct 8 ms 14288 KB Output is correct
12 Correct 10 ms 14288 KB Output is correct
13 Correct 9 ms 14352 KB Output is correct
14 Correct 10 ms 14288 KB Output is correct
15 Correct 9 ms 14288 KB Output is correct
16 Correct 9 ms 14288 KB Output is correct
17 Correct 9 ms 14288 KB Output is correct
18 Correct 9 ms 14288 KB Output is correct
19 Correct 9 ms 14288 KB Output is correct
20 Correct 9 ms 14416 KB Output is correct
21 Correct 9 ms 14380 KB Output is correct
22 Correct 9 ms 14416 KB Output is correct
23 Correct 9 ms 14416 KB Output is correct
24 Correct 14 ms 14456 KB Output is correct
25 Correct 12 ms 14428 KB Output is correct
26 Correct 10 ms 14416 KB Output is correct
27 Correct 10 ms 14416 KB Output is correct
28 Correct 9 ms 14416 KB Output is correct
29 Correct 10 ms 14464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14288 KB Output is correct
2 Correct 9 ms 14356 KB Output is correct
3 Correct 8 ms 14288 KB Output is correct
4 Correct 8 ms 14288 KB Output is correct
5 Correct 8 ms 14404 KB Output is correct
6 Correct 8 ms 14340 KB Output is correct
7 Correct 9 ms 14288 KB Output is correct
8 Correct 8 ms 14388 KB Output is correct
9 Correct 8 ms 14288 KB Output is correct
10 Correct 9 ms 14288 KB Output is correct
11 Correct 8 ms 14288 KB Output is correct
12 Correct 10 ms 14288 KB Output is correct
13 Correct 9 ms 14352 KB Output is correct
14 Correct 10 ms 14288 KB Output is correct
15 Correct 9 ms 14288 KB Output is correct
16 Correct 9 ms 14288 KB Output is correct
17 Correct 9 ms 14288 KB Output is correct
18 Correct 9 ms 14288 KB Output is correct
19 Correct 9 ms 14288 KB Output is correct
20 Correct 9 ms 14416 KB Output is correct
21 Correct 9 ms 14380 KB Output is correct
22 Correct 9 ms 14416 KB Output is correct
23 Correct 9 ms 14416 KB Output is correct
24 Correct 14 ms 14456 KB Output is correct
25 Correct 12 ms 14428 KB Output is correct
26 Correct 10 ms 14416 KB Output is correct
27 Correct 10 ms 14416 KB Output is correct
28 Correct 9 ms 14416 KB Output is correct
29 Correct 10 ms 14464 KB Output is correct
30 Correct 29 ms 15688 KB Output is correct
31 Correct 13 ms 15024 KB Output is correct
32 Correct 27 ms 16864 KB Output is correct
33 Correct 26 ms 16408 KB Output is correct
34 Correct 64 ms 18692 KB Output is correct
35 Correct 50 ms 17316 KB Output is correct
36 Correct 52 ms 16512 KB Output is correct
37 Correct 37 ms 16436 KB Output is correct
38 Correct 35 ms 16200 KB Output is correct
39 Correct 49 ms 16176 KB Output is correct
40 Correct 89 ms 18704 KB Output is correct
41 Correct 45 ms 17452 KB Output is correct
42 Correct 38 ms 17048 KB Output is correct
43 Correct 42 ms 17196 KB Output is correct
44 Incorrect 222 ms 17752 KB Wrong Answer[1]
45 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14288 KB Output is correct
2 Correct 9 ms 14356 KB Output is correct
3 Correct 8 ms 14288 KB Output is correct
4 Correct 8 ms 14288 KB Output is correct
5 Correct 8 ms 14404 KB Output is correct
6 Correct 8 ms 14340 KB Output is correct
7 Correct 9 ms 14288 KB Output is correct
8 Correct 8 ms 14388 KB Output is correct
9 Correct 8 ms 14288 KB Output is correct
10 Correct 9 ms 14288 KB Output is correct
11 Correct 8 ms 14288 KB Output is correct
12 Correct 10 ms 14288 KB Output is correct
13 Correct 9 ms 14352 KB Output is correct
14 Correct 10 ms 14288 KB Output is correct
15 Correct 9 ms 14288 KB Output is correct
16 Correct 9 ms 14288 KB Output is correct
17 Correct 9 ms 14288 KB Output is correct
18 Correct 9 ms 14288 KB Output is correct
19 Correct 9 ms 14288 KB Output is correct
20 Correct 9 ms 14416 KB Output is correct
21 Correct 9 ms 14380 KB Output is correct
22 Correct 9 ms 14416 KB Output is correct
23 Correct 9 ms 14416 KB Output is correct
24 Correct 14 ms 14456 KB Output is correct
25 Correct 12 ms 14428 KB Output is correct
26 Correct 10 ms 14416 KB Output is correct
27 Correct 10 ms 14416 KB Output is correct
28 Correct 9 ms 14416 KB Output is correct
29 Correct 10 ms 14464 KB Output is correct
30 Correct 29 ms 15688 KB Output is correct
31 Correct 13 ms 15024 KB Output is correct
32 Correct 27 ms 16864 KB Output is correct
33 Correct 26 ms 16408 KB Output is correct
34 Correct 64 ms 18692 KB Output is correct
35 Correct 50 ms 17316 KB Output is correct
36 Correct 52 ms 16512 KB Output is correct
37 Correct 37 ms 16436 KB Output is correct
38 Correct 35 ms 16200 KB Output is correct
39 Correct 49 ms 16176 KB Output is correct
40 Correct 89 ms 18704 KB Output is correct
41 Correct 45 ms 17452 KB Output is correct
42 Correct 38 ms 17048 KB Output is correct
43 Correct 42 ms 17196 KB Output is correct
44 Incorrect 222 ms 17752 KB Wrong Answer[1]
45 Halted 0 ms 0 KB -