Submission #386779

#TimeUsernameProblemLanguageResultExecution timeMemory
386779talant117408Cop and Robber (BOI14_coprobber)C++17
100 / 100
673 ms7660 KiB
#include "coprobber.h"
//~ #include "grader.cpp"
#include <bits/stdc++.h>
 
using namespace std;
 
typedef tuple <int, int, int> Position;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
 
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define eps (double)1e-9
#define PI 2*acos(0.0)
#define endl "\n"
#define sz(v) int((v).size())
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define OK cout << "OK" << endl;

const int COP = 0, ROBBER = 1;
int leftToWin[2][MAX_N][MAX_N], nxtPos[MAX_N][MAX_N];

int start(int N, bool A[MAX_N][MAX_N]) {
	for (int i = 0; i < N; i++) {
		int degree = count(A[i], A[i]+N, true);
		for (int j = 0; j < N; j++) {
			if (j != i) {
				leftToWin[COP][j][i] = 1;
				leftToWin[ROBBER][j][i] = degree;
			}
		}
	}
	queue <Position> K;
	for (int i = 0; i < N; i++) {
		K.push(Position(COP, i, i));
		K.push(Position(ROBBER, i, i));
	}
	
	int cnt = 0;
	while (!K.empty()) {
		int t, c, r;
		tie(t, c, r) = K.front(); K.pop();
		cnt++;
		if (t == COP) {
			for (int j = 0; j < N; j++) {
				if (A[r][j] && leftToWin[ROBBER][c][j]) {
					leftToWin[ROBBER][c][j]--;
					if (leftToWin[ROBBER][c][j] == 0) {
						K.push(Position(ROBBER, c, j));
					}
				}
			}
		}
		else {
			for (int j = 0; j < N; j++) {
				if ((j == c || A[c][j]) && leftToWin[COP][j][r]) {
					leftToWin[COP][j][r] = 0;
					K.push(Position(COP, j, r));
					nxtPos[j][r] = c;
				}
			}
		}
	}
	
    return cnt == 2*N*N ? 0 : -1;
}

int cop;

int nextMove(int R) {
	cop = nxtPos[cop][R];
    return cop;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...