Submission #377220

# Submission time Handle Problem Language Result Execution time Memory
377220 2021-03-13T12:09:46 Z Kevin_Zhang_TW Cop and Robber (BOI14_coprobber) C++17
Compilation error
0 ms 0 KB
#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);
}
 
// don't modify the main function
int32_t main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
    int N;
    cin >> N;
    bool A[MAX_N][MAX_N];
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin >> A[i][j];
        }
    }
    int P = start(N,A);
    cout << P << endl;
    int R;
    cin >> R;
    while (true) {
        if (P == R) break;
        P = nextMove(R);
        cout << P << endl;
        if (P == R) break;
        cin >> R;
    }
}

Compilation message

/tmp/ccrZYvXg.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/cc9Oeh6i.o:coprobber.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status