Submission #587383

# Submission time Handle Problem Language Result Execution time Memory
587383 2022-07-01T18:17:27 Z mohammad_kilani Game (APIO22_game) C++17
30 / 100
117 ms 262144 KB
#include "game.h"
#include <bits/stdc++.h>
using namespace std;

#define oo 1000000010

vector< vector< vector< int > > > g , g2;

vector< int > mn , mx , last , last2;

int n , k;


void init(int n, int k) {
	::n = n;
	::k = k;
	g.resize(n , vector< vector< int > > (k + 1));
	g2.resize(n , vector< vector< int >  > (k + 1));
	mn.resize(n);
	mx.resize(n);
	last.resize(n , 0);
	last2.resize(n , k);
	for(int i = 0 ;i < k;i++){
		mn[i] = mx[i] = i;
	}
	for(int i = k ;i < n;i++){
		mn[i] = k;
		mx[i] = k;
	}
}

void CheckMax(int u){
	if(mx[u] == k) return;
	int i = k , node;
	while((i == k || i < mx[u])){
		while((int)g[u][i].size() > 0){
			node = g[u][i].back();
			g[u][i].pop_back();
			if(mx[node] != k && mx[node] >= mx[u]){
				g[u][mx[node]].push_back(node);
				continue;
			}
			mx[node] = mx[u];
			g[u][mx[node]].push_back(node);
			CheckMax(node);
		}
		i = last[u];
		if(last[u] < mx[u])
			last[u]++;
	}
}

void CheckMin(int u){
	if(mn[u] == k) return;

	int i = k , node;
	while(i > mn[u]){
		while((int)g2[u][i].size() > 0){
			node = g2[u][i].back();
			g2[u][i].pop_back();

			if(mn[node] <= mn[u]){
				g2[u][mn[node]].push_back(node);
				continue;
			}
			mn[node] = mn[u];
			g2[u][mn[node]].push_back(node);
			CheckMin(node);

		}
		i = last2[u];
		if(last2[u] > mn[u])
			last2[u]--;
	}
}

int add_teleporter(int u, int v) {
	if(u < k && v < k){
		if(u >= v)
			return 1;
		return 0;
	}

	//mx[v] 

	if(mx[u] != k && (mx[v] < mx[u] || mx[v] == k)){
		g[u][k].push_back(v);
		CheckMax(u);
	}
	else
		g[u][mx[v]].push_back(v);

	if(mn[u] > mn[v]){
		g2[v][k].push_back(u);
		CheckMin(v);
	}
	else
		g2[v][mn[u]].push_back(u);

	if(u < k) u = v;
	if(mn[u] <= mx[u] && (mx[u] != k)){
		return 1;
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 720 KB Output is correct
4 Correct 0 ms 336 KB Output is correct
5 Correct 1 ms 720 KB Output is correct
6 Correct 1 ms 720 KB Output is correct
7 Correct 1 ms 720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 720 KB Output is correct
4 Correct 0 ms 336 KB Output is correct
5 Correct 1 ms 720 KB Output is correct
6 Correct 1 ms 720 KB Output is correct
7 Correct 1 ms 720 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 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 464 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 720 KB Output is correct
4 Correct 0 ms 336 KB Output is correct
5 Correct 1 ms 720 KB Output is correct
6 Correct 1 ms 720 KB Output is correct
7 Correct 1 ms 720 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 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 464 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
20 Correct 2 ms 848 KB Output is correct
21 Correct 4 ms 5072 KB Output is correct
22 Correct 4 ms 5200 KB Output is correct
23 Correct 1 ms 848 KB Output is correct
24 Correct 45 ms 31740 KB Output is correct
25 Correct 20 ms 14416 KB Output is correct
26 Correct 7 ms 5328 KB Output is correct
27 Correct 21 ms 24012 KB Output is correct
28 Correct 16 ms 23112 KB Output is correct
29 Correct 18 ms 23100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 720 KB Output is correct
4 Correct 0 ms 336 KB Output is correct
5 Correct 1 ms 720 KB Output is correct
6 Correct 1 ms 720 KB Output is correct
7 Correct 1 ms 720 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 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 464 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
20 Correct 2 ms 848 KB Output is correct
21 Correct 4 ms 5072 KB Output is correct
22 Correct 4 ms 5200 KB Output is correct
23 Correct 1 ms 848 KB Output is correct
24 Correct 45 ms 31740 KB Output is correct
25 Correct 20 ms 14416 KB Output is correct
26 Correct 7 ms 5328 KB Output is correct
27 Correct 21 ms 24012 KB Output is correct
28 Correct 16 ms 23112 KB Output is correct
29 Correct 18 ms 23100 KB Output is correct
30 Correct 111 ms 146084 KB Output is correct
31 Runtime error 117 ms 262144 KB Execution killed with signal 9
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 720 KB Output is correct
4 Correct 0 ms 336 KB Output is correct
5 Correct 1 ms 720 KB Output is correct
6 Correct 1 ms 720 KB Output is correct
7 Correct 1 ms 720 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 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 464 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
20 Correct 2 ms 848 KB Output is correct
21 Correct 4 ms 5072 KB Output is correct
22 Correct 4 ms 5200 KB Output is correct
23 Correct 1 ms 848 KB Output is correct
24 Correct 45 ms 31740 KB Output is correct
25 Correct 20 ms 14416 KB Output is correct
26 Correct 7 ms 5328 KB Output is correct
27 Correct 21 ms 24012 KB Output is correct
28 Correct 16 ms 23112 KB Output is correct
29 Correct 18 ms 23100 KB Output is correct
30 Correct 111 ms 146084 KB Output is correct
31 Runtime error 117 ms 262144 KB Execution killed with signal 9
32 Halted 0 ms 0 KB -