This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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();
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;
q.push({1, X.C, z});
}
}
}
else{
if (!bio[0][X.C][X.R]){
best[X.C][X.R] = X.C;
bio[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]){
best[z][X.R] = X.C;
bio[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 -= bio[0][i][j];
if (num == 0) idx = i;
}
curr = idx; return idx;
}
int nextMove(int R){
return curr = best[curr][R];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |