Submission #413547

# Submission time Handle Problem Language Result Execution time Memory
413547 2021-05-28T21:57:24 Z Blagojce Cop and Robber (BOI14_coprobber) C++11
0 / 100
320 ms 3904 KB
#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x), end(x)
  
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pii;
const ll inf = 1e18;
const int i_inf = 1e9;
const ll mod = 1e9+7;
  
const int mxn = 505;
 
 
#include "coprobber.h"
 
 
 
int n;
vector<int> g[mxn];
vector<int> gc[mxn];
 
bool bad[mxn][mxn];
int nxt[mxn][mxn];
 
bool update_status(int u, int v){
	if(bad[u][v]) return false;
	for(auto e1 : gc[u]){
		bool ok = true;
		for(auto e2 : g[v]){
			ok &= bad[e1][e2];
		}
		bad[u][v] |= ok;
		if(ok){
			nxt[u][v] = e1;
			return true;
		}
	}
	return false;
}
int cop;

int dist[mxn][mxn];

int start(int N, bool A[MAX_N][MAX_N])
{
	n = N;
	fr(i, 0, n){
		gc[i].pb(i);
		fr(j, 0, n){
			if(A[i][j]){
				g[i].pb(j);
				gc[i].pb(j);
			}
		}
	}
	fr(i, 0, n){
		fr(j, 0, n){
			if(i == j || A[i][j]){
				bad[i][j] = true;
				nxt[i][j] = j;
			}
		}
	}
	fr(i, 0, n){
		fr(j, 0, n){
			if(i == j) dist[i][j] = 0;
			else if(A[i][j]) dist[i][j] = 1;
			else dist[i][j] = 1e9;
		}
	}
	
	fr(k, 0, n){
		fr(i, 0, n){
			fr(j, 0, n){
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}
	
	
	
	
	fr(k, 0, n){
		fr(i, 0, n){
			fr(j, 0, n){
				if(dist[i][j] != k) continue;
				update_status(i, j);
			}
		}
	}
	fr(i, 0, n){
		bool cand = true;
		fr(j, 0, n){
			cand &= bad[i][j];
		}
		if(cand){
			cop = i;
			return i;
		}
	}
	return -1;
}
int nextMove(int R)
{	
	cop = nxt[cop][R];
	return cop;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 320 ms 3904 KB Output is correct
5 Incorrect 50 ms 1864 KB Cop can catch the robber, but start() returned -1
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Incorrect 1 ms 328 KB Cop can catch the robber, but start() returned -1
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Incorrect 1 ms 328 KB Cop can catch the robber, but start() returned -1
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 320 ms 3904 KB Output is correct
5 Incorrect 50 ms 1864 KB Cop can catch the robber, but start() returned -1
6 Halted 0 ms 0 KB -