Submission #854014

#TimeUsernameProblemLanguageResultExecution timeMemory
854014fabijan_cikacCop and Robber (BOI14_coprobber)C++17
0 / 100
1 ms6488 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];
     
    //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));
    	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] = x;
    				for (int z: v[x]){
    					tmp2[0][x][y] |= tmp[1][z][y];
    					if (tmp[1][z][y] == 1)
    						best[x][y] = z;
    				}
    				//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;
    			}
    		}
    		
    		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(){
    	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...