Submission #854310

#TimeUsernameProblemLanguageResultExecution timeMemory
854310fabijan_cikacCop and Robber (BOI14_coprobber)C++17
100 / 100
259 ms11916 KiB
#include <bits/stdc++.h>
 
using namespace std;
 
#define pb push_back

//T = 0 - policajac na redu
struct state{
	int T, C, R;
};
 
const int N = 500;
 
vector<int> v[N];

int bio[2][N][N], dp[2][N][N];
int cnt[N][N], best[N][N]; int curr;
int start(int n, bool a[N][N]){
	for (int i = 0; i < n; ++i){
		for (int j = 0; j < n; ++j){
			if (a[i][j]) v[i].pb(j);
		}
	}
	
	queue<state> q;
	for (int i = 0; i < n; ++i){
		q.push({0, i, i}); q.push({1, i, i});
		bio[0][i][i] = 1; bio[1][i][i] = 1;
		dp[0][i][i] = 1; dp[1][i][i] = 1;
	}
	for (int i = 0; i < n; ++i){
		for (int j = 0; j < n; ++j)
			cnt[i][j] = (int)(v[j].size());
	}
	
	memset(best, -1, sizeof(best));
	while (!q.empty()){
		state X = q.front(); q.pop();
		//cout << X.T << ' ' << X.C << ' ' << X.R << endl;
		//cout << "!!!! " << cnt[0][1] << endl;
		if (!X.T){
			for (int z: v[X.R]){
				--cnt[X.C][z];
				if (cnt[X.C][z] == 0){
					bio[1][X.C][z] = 1; dp[1][X.C][z] = 1;
					q.push({1, X.C, z});
				}
			}
		}
		else{
			if (!bio[0][X.C][X.R]){
				if (best[X.C][X.R] == -1) best[X.C][X.R] = X.C;
				bio[0][X.C][X.R] = 1; dp[0][X.C][X.R] = 1;
				q.push({0, X.C, X.R});
			}
			for (int z: v[X.C]){
				if (!bio[0][z][X.R]){
					if (best[z][X.R] == -1) best[z][X.R] = X.C;
					bio[0][z][X.R] = 1; dp[0][z][X.R] = 1;
					q.push({0, z, X.R});
				}
			}
		}
	}
	
	int idx = -1;
	for (int i = 0; i < n; ++i){
		int num = n;
		for (int j = 0; j < n; ++j)
			num -= dp[0][i][j];
		if (num == 0) idx = i;
	}
	
	curr = idx; return idx;
}
 
int nextMove(int R){
	return curr = best[curr][R];
}

/*bool A[N][N];
int main(){
	int n; cin >> n;
	for (int i = 0; i < n; ++i){
		for (int j = 0; j < n; ++j)
			cin >> A[i][j];
	}
	cout << start(n, A) << endl;
	while (1){
		int x; cin >> x;
		if (x == -1) break;
		cout << nextMove(x) << endl;
	}
}*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...