Submission #1216623

#TimeUsernameProblemLanguageResultExecution timeMemory
1216623stdfloatCop and Robber (BOI14_coprobber)C++20
0 / 100
1 ms2376 KiB
#include <bits/stdc++.h>
#include "coprobber.h"
// #include "grader.cpp"
using namespace std;

#define sz(v)	(int)(v).size()

int dp[501][501][2], cnt[501][501][2];

vector<vector<int>> E, G;

int start(int n, bool A[MAX_N][MAX_N]) {
	E.assign(n, {});
	G.assign(n, {});
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (A[i][j]) {
				E[i].push_back(j);
				G[j].push_back(i);
			}
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < 2; k++)
				cnt[i][j][k] = sz(E[(k ? j : i)]);
		}
	}

	memset(dp, -1, sizeof dp);

	queue<pair<pair<int, int>, bool>> q;
	for (int i = 0; i < n; i++) {
		dp[i][i][0] = 1;
		dp[i][i][1] = 0;
		q.push({{i, i}, false});
		q.push({{i, i}, true});
	}

	while (!q.empty()) {
		auto [d, tr] = q.front(); q.pop();
		auto [x, y] = d;

		if (!tr) {
			if (!dp[x][y][0]) {
				for (auto j : G[x]) {
					if (~dp[j][y][1]) assert(dp[j][y][1]);
					else {
						dp[j][y][1] = 1;
						q.push({{j, y}, true});
					}
				}
			}
			else {
				for (auto j : G[x]) {
					if (~dp[j][y][1]) continue;

					if (!--cnt[j][y][1]) {
						dp[j][y][1] = 0;
						q.push({{j, y}, true});
					}
				}
			}
		}
		else {
			if (!dp[x][y][1]) {
				for (auto j : G[y]) {
					if (~dp[x][j][0]) assert(dp[j][y][0]);
					else {
						dp[x][j][0] = 1;
						q.push({{x, j}, false});
					}
				}
			}
			else {
				for (auto j : G[y]) {
					if (~dp[x][j][0]) continue;

					if (!--cnt[x][j][0]) {
						dp[x][j][0] = 0;
						q.push({{x, j}, false});
					}
				}
			}
		}
	}

	for (int i = 0; i < n; i++) {
		bool tr = true;
		for (int j = 0; j < n && tr; j++)
			tr = dp[i][j][0] == 1;

		if (tr) return i;
	}

	return -1;
}

int nextMove(int R) {
	return -1;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...