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>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define N 2000003
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll INF = 1e18, MOD = 1e9 + 7, MOD2 = 1e6 + 3;
int d[N], dg[N], m, n;
int u[N], mv[N], gl;
vector <int> g[N];
void print (int s) {
cout << (s / 2) / n << ' ' << (s / 2) % n << ' ' << s % 2 << endl;
}
int start (int v, bool A[][500]) {
n = v;
m = 2 * n * n;
for (int i = 0; i < m; i++) {
int x = (i / 2) / n;
int y = (i / 2) % n;
d[i] = 2;
if (i & 1) {
for (int j = 0; j < n; j++) {
if (A[y][j]) {
dg[i]++, dg[2 * (x * n + j)]++;
g[2 * (x * n + j)].push_back (i);
}
}
} else {
for (int j = 0; j < n; j++) {
if (A[x][j]) {
dg[i]++, dg[2 * (j * n + y) + 1]++;
g[2 * (j * n + y) + 1].push_back (i);
}
}
}
}
for (int i = 0; i < m; i += 2)
g[i].push_back (i + 1);
queue <int> q;
for (int i = 0; i < n; i++) {
int s = 2 * (i * n + i);
d[s] = 1;
d[s + 1] = 0;
q.push (s), q.push (s + 1);
}
while (!q.empty ()) {
int s = q.front ();
q.pop ();
if (u[s]) continue;
u[s] = 1;
if (!d[s]) {
for (int to : g[s]) {
if (u[to]) continue;
u[to] = 1, d[to] = 1;
q.push (to);
mv[to] = s;
}
} else {
for (int to : g[s]) {
if (u[to]) continue;
if (--dg[to] == 0) {
u[to] = 1, d[to] = 0;
q.push (to);
}
}
}
}
for (int i = 0; i < n; i++) {
int x = 1;
for (int j = 0; j < n; j++) {
if (d[2 * (i * n + j)] != 1) {
x = 0;
break;
}
}
if (x) {
gl = i;
return gl;
}
}
return -1;
}
int nextMove (int x) {
int s = 2 * (gl * n + x);
s = mv[s];
gl = (s / 2) / n;
return gl;
}
# | 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... |