Submission #377221

#TimeUsernameProblemLanguageResultExecution timeMemory
377221Kevin_Zhang_TW경찰관과 강도 (BOI14_coprobber)C++17
100 / 100
1385 ms11964 KiB
#include<bits/stdc++.h>
#define pb emplace_back
#define AI(i) begin(i), end(i)
using namespace std;
using ll = long long;
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() {cerr << endl;}
template<class T, class ...U> void kout (T v, U ...e) { cerr << v << ' ', kout(e...); }
template<class T> void debug(T L, T R) { while (L != R) cerr << *L << " \n"[next(L)==R], ++L; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
// What I should check
// 1. overflow
// 2. corner cases
// Enjoy the problem instead of hurrying to AC
// Good luck !
const int MAX_N = 500;
 
// modify the following functions
// you can define global variables and functions
 
int cop[MAX_N][MAX_N], rob[MAX_N][MAX_N], N;
int capchance[MAX_N][MAX_N], eschance[MAX_N][MAX_N], ti;
int inq[2][MAX_N][MAX_N];
bool E[MAX_N][MAX_N];
 
#pragma GCC optimize("Ofast")
 
void finishdp() {
	const int cop_t = 0, rob_t = 1;
	queue< tuple<int,int,int,int> > q;
 
	for (int i = 0;i < N;++i) q.emplace(rob_t, i, i, true);
 
	auto qpush = [&](int t, int i, int j, int k) {
		if (inq[t][i][j]) return;
		inq[t][i][j] = true;
		q.emplace(t, i, j, k);
	};
 
	while (q.size()) {
		auto [t, i, j, res] = q.front(); q.pop();
		if (t == cop_t) {
			if (~cop[i][j]) continue;
			cop[i][j] = res;
			if (res == false) {
				for (int k = 0;k < N;++k) 
					if (E[j][k]) 
						qpush(rob_t, i, k, false);
			}
			else {
				cop[i][j] = ++ti;
				for (int k = 0;k < N;++k) 
					if (E[j][k]) {
						if (--eschance[i][k] == 0)
							qpush(rob_t, i, k, true);
					}
			}
		}
		else {
			if (~rob[i][j]) continue;
			rob[i][j] = res;
			if (res == true) {
				rob[i][j] = ++ti;
				for (int k = 0;k < N;++k) 
					if (k == i || E[i][k]) 
						qpush(cop_t, k, j, true);
			}
			else {
				for (int k = 0;k < N;++k) 
					if (k == i || E[i][k]) {
						if (--capchance[j][k] == 0)
							qpush(cop_t, k, j, false);
					}
			}
		} 
	}
}
int cur;
 
int start(int N, bool A[MAX_N][MAX_N]) {
	::N = N;
	memcpy(E, A, sizeof(E));
	memset(cop, -1, sizeof(cop));
	memset(rob, -1, sizeof(rob));
 
	for (int i = 0;i < N;++i)
		for (int j = 0;j < N;++j) 
		 	for (int k = 0;k < N;++k)  {
				if (E[j][k]) 
					++eschance[i][j];
				if (E[j][k] || j == k) 
					++capchance[i][j];
			}
 
	finishdp();
 
	for (int i = 0;i < N;++i)
		if (count(cop[i], cop[i] + N, false) + count(cop[i], cop[i] + N, -1) == 0)
			return cur = i;
 
	return -1;
}
int nextMove(int R) {
 
	if (E[cur][R]) return R;
 
	for (int i = 0;i < N;++i) if (i == cur || E[cur][i])  {
		if (cop[i][R] > 0 && cop[cur][R] > rob[i][R])
			return cur = i;
	}
 
	assert(false);
}
 
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...