Submission #587376

# Submission time Handle Problem Language Result Execution time Memory
587376 2022-07-01T17:58:28 Z mohammad_kilani Game (APIO22_game) C++17
2 / 100
1 ms 720 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[v] < mx[u] && (mx[u] != k)) || (mx[v] == k && mn[u] != 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(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 0 ms 208 KB Output is correct
3 Correct 1 ms 720 KB Output is correct
4 Correct 1 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 0 ms 208 KB Output is correct
3 Correct 1 ms 720 KB Output is correct
4 Correct 1 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 Incorrect 0 ms 336 KB Wrong Answer[1]
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 720 KB Output is correct
4 Correct 1 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 Incorrect 0 ms 336 KB Wrong Answer[1]
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 720 KB Output is correct
4 Correct 1 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 Incorrect 0 ms 336 KB Wrong Answer[1]
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 720 KB Output is correct
4 Correct 1 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 Incorrect 0 ms 336 KB Wrong Answer[1]
12 Halted 0 ms 0 KB -