# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
854008 | fabijan_cikac | Cop and Robber (BOI14_coprobber) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "coprobber.h"
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 solve(int n, bool a[N][N]){
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 best[curr][R];
}
/*int main(){
return 0;
}*/