Submission #854015

#TimeUsernameProblemLanguageResultExecution timeMemory
854015fabijan_cikacCop and Robber (BOI14_coprobber)C++17
60 / 100
3054 ms7252 KiB
#include <bits/stdc++.h>
#include "coprobber.h"
#define MAXN 500
 
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
int tmp[2][N][N], tmp2[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][i][i] = 1; tmp[1][i][i] = 1;
	}
	
	memset(best, -1, sizeof(best));
	cout << endl;
	for (int i = 0; i < n + 1; ++i){
		for (int x = 0; x < n; ++x){
			for (int y = 0; y < n; ++y){
				//b = 0
				tmp2[0][x][y] = 0;
				if (x == y) tmp2[0][x][y] = 1;
				tmp2[0][x][y] |= tmp[1][x][y];
				if (tmp[1][x][y] == 1 && best[x][y] == -1)
					best[x][y] = x;
				for (int z: v[x]){
					tmp2[0][x][y] |= tmp[1][z][y];
					if (tmp[1][z][y] == 1 && best[x][y] == -1)
						best[x][y] = z;
				}
				//if (i == 1) cout << tmp2[0][x][y] << ' ';
				//b = 1
				tmp2[1][x][y] = 0;
				if (x == y) tmp2[1][x][y] = 1;
				int cnt = 0;
				for (int z: v[y]) cnt += tmp[0][x][z];
				if (cnt == (int)(v[y].size()))
					tmp2[1][x][y] = 1;
			}
			//if (i == 1) cout << endl;
		}
		
		for (int x = 0; x < n; ++x){
			for (int y = 0; y < n; ++y)
				tmp[0][x][y] = tmp2[0][x][y], tmp[1][x][y] = tmp2[1][x][y];
		}
	}
	
	int idx = -1;
	for (int i = 0; i < n; ++i){
		bool B = 1;
		for (int j = 0; j < n; ++j){
			if (tmp[0][i][j] == 0) B = 0;
		}
		if (B) idx = i;
	}
	
	return curr = idx;
}
 
int nextMove(int R){
	return curr = best[curr][R];
}
 
/*int main(){
	int n; cin >> n;
	for (int i = 0; i < n; ++i){
		for (int j = 0; j < n; ++j)
			cin >> A[i][j];
	}
	cout << start(n, A) << endl;
	while (1){
		int x; cin >> x;
		if (x == -1) break;
		cout << "!!! " << nextMove(x) << endl;
	}
	return 0;
}
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...