Submission #854019

#TimeUsernameProblemLanguageResultExecution timeMemory
854019fabijan_cikacCop and Robber (BOI14_coprobber)C++17
60 / 100
3032 ms4156 KiB
#include <bits/stdc++.h>
#define MAXN 500

#pragma GCC optimize("O3")

using namespace std;
 
#define pb push_back
 
const int N = 510;
 
vector<int> v[N];
int best[N][N];
bool A[MAXN][MAXN];
 
//tmp[b][x][y] - ako se policajac nalazi na poziciji x, pljackas na y te je b na redu moze li policajac uloviti lopova
bool tmp[2][2][N][N]; int curr;
int start(int n, bool a[MAXN][MAXN]){
	for (int i = 0; i < n; ++i){
		for (int j = 0; j < n; ++j){
			if (a[i][j] == 1) v[i].pb(j);
		}
	}
	for (int i = 0; i < n; ++i){
		tmp[0][0][i][i] = 1; tmp[0][1][i][i] = 1;
	}
	
	memset(best, -1, sizeof(best));
	for (int i = 0; i < n + 3; ++i){
		int L = (i & 1);
		for (int x = 0; x < n; ++x){
			for (int y = 0; y < n; ++y){
				//b = 0
				tmp[!L][0][x][y] = 0;
				if (x == y) tmp[!L][0][x][y] = 1;
				tmp[!L][0][x][y] |= tmp[L][1][x][y];
				if (tmp[L][1][x][y] == 1 && best[x][y] == -1)
					best[x][y] = x;
				for (int z: v[x]){
					tmp[!L][0][x][y] |= tmp[L][1][z][y];
					if (tmp[L][1][z][y] == 1 && best[x][y] == -1)
						best[x][y] = z;
				}
				tmp[!L][1][x][y] = 0;
				if (x == y) tmp[!L][1][x][y] = 1;
				int cnt = 0;
				for (int z: v[y]) cnt += tmp[L][0][x][z];
				if (cnt == (int)(v[y].size()))
					tmp[!L][1][x][y] = 1;
			}
		}
	}
	
	int idx = -1;
	for (int i = 0; i < n; ++i){
		int cnt = 0;
		for (int j = 0; j < n; ++j)
			cnt += tmp[0][0][i][j];
		if (cnt == n) idx = i;
	}
	
	return curr = idx;
}
 
int nextMove(int R){
	return curr = best[curr][R];
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...