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 "coprobber.h"
#include <bits/stdc++.h>
using namespace std;
const int maxN = 500;
const int M = 2 * maxN * maxN;
vector<int> g[maxN];
int good[M];
unsigned int d[M];
int siz[M];
int pos[M];
//0 if it's officer's turn, 1 if robber's one
int enc(int officerPos, int robberPos, int whoseTurn) {
return whoseTurn * maxN * maxN + officerPos * maxN + robberPos;
}
inline void expand(int cur) {
if (d[cur] == siz[cur] || (cur / (maxN * maxN) == 0 && d[cur]))
good[cur] = pos[cur];
if (good[cur] != -1) {
int officerPos = cur % (maxN * maxN) / maxN;
int robberPos = cur % maxN;
if (cur / (maxN * maxN)) { //robber's turn
int j = enc(officerPos, robberPos, 0);
if (good[j] == -1) {
d[j]++;
pos[j] = cur;
expand(j);
}
for (int i : g[officerPos]) {
j = enc(i, robberPos, 0);
if (good[j] == -1) {
d[j]++;
pos[j] = cur;
expand(j);
}
}
} else { //officer's turn
for (int i : g[robberPos]) {
int j = enc(officerPos, i, 1);
if (good[j] == -1) {
d[j]++;
pos[j] = cur;
expand(j);
}
}
}
}
}
int loc;
int start(int N, bool A[MAX_N][MAX_N]) {
memset(siz, 0, sizeof siz);
for (int i = 0; i < M; i++)
pos[i] = -2;
memset(good, -1, sizeof good);
memset(d, 0, sizeof d);
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
if (A[i][j])
g[i].push_back(j);
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
if (i != j) {
siz[enc(i, j, 0)]++;
siz[enc(i, j, 0)] += g[i].size();
siz[enc(i, j, 1)] += g[j].size();
}
for (int i = 0; i < N; i++) {
expand(enc(i, i, 0));
expand(enc(i, i, 1));
}
for (int i = 0; i < N; i++) {
bool no = 0;
for (int j = 0; j < N; j++)
no |= good[enc(i, j, 0)] == -1;
if (!no) {
loc = i;
return i;
}
}
return -1;
}
int nextMove(int R) {
//cout << loc << " " << R << endl;
loc = good[enc(loc, R, 0)] % (maxN * maxN) / maxN;
return loc;
}
Compilation message (stderr)
coprobber.cpp: In function 'void expand(int)':
coprobber.cpp:20:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (d[cur] == siz[cur] || (cur / (maxN * maxN) == 0 && d[cur]))
~~~~~~~^~~~~~~~~~~
# | 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... |