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 "Anthony.h"
#include <bits/stdc++.h>
using namespace std;
std::vector<int> Mark(int N, int M, int A, int B,
std::vector<int> U, std::vector<int> V) {
std::vector<int> X(M, -1);
vector<vector<pair<int, int>>> adj(N);
for (int i = 0; i < M; ++i) {
adj[U[i]].push_back({V[i], i});
adj[V[i]].push_back({U[i], i});
}
vector<int> dist(N, -1), par(N), e(N, -1), ord;
dist[0] = 0;
queue<int> q;
q.push(0);
while (!q.empty()) {
int v = q.front();
q.pop();
ord.push_back(v);
for (auto [to, i] : adj[v]) {
if (dist[to] == -1) {
dist[to] = dist[v] + 1;
par[to] = v;
e[to] = i;
q.push(to);
}
}
}
if (A >= 3) {
for (int i = 0; i < M; ++i) {
if (dist[U[i]] > dist[V[i]]) {
swap(U[i], V[i]);
}
X[i] = dist[U[i]] % 3;
}
} else {
vector<int> code{0, 1, 0, 0, 1, 1};
vector<int> dp(N, -1);
for (int x : ord) {
if (par[x] && adj[par[x]].size() >= 3) {
if (X[e[par[x]]] == 1) {
dp[x] = 0;
} else {
dp[x] = 1;
}
} else if (x == 0) {
dp[x] = -1;
} else {
dp[x] = (1 + dp[par[x]]) % size(code);
}
if (dp[x] >= 0) {
X[e[x]] = code[dp[x]];
}
}
}
assert(find(X.begin(), X.end(), -1) == X.end());
return X;
}
#include "Catherine.h"
#include <assert.h>
#include <algorithm>
#include <string>
#include <vector>
namespace {
using std::string;
int A, B;
int last = -1;
bool known = false;
string seq = "";
} // namespace
void Init(int A, int B) {
::A = A;
::B = B;
}
int Move(std::vector<int> y) {
int ans = -2;
auto yy = y;
if (last != -1) {
++yy[last];
}
if (A == 2) {
int deg = 0;
for (int k = 0; k < 2; ++k) {
deg += yy[k];
}
if (deg == 2) {
if (known) {
assert(std::count(y.begin(), y.end(), 1) == 1);
ans = std::find(y.begin(), y.end(), 1) - y.begin();
} else {
for (int k = 0; k < 2; ++k) {
seq += string(y[k], static_cast<char>('0' + k));
}
if (seq.size() == 5) {
bool rev = false;
for (int rot = 0; rot < 6; ++rot) {
if (seq == string("010011010011").substr(rot, 5)) {
rev = true;
}
}
known = true;
if (rev) {
ans = -1;
} else {
assert(std::count(y.begin(), y.end(), 1) == 1);
ans = std::find(y.begin(), y.end(), 1) - y.begin();
}
} else {
ans = seq.back() - '0';
}
}
} else {
known = true;
assert(std::count(yy.begin(), yy.end(), 1) == 1);
ans = std::find(yy.begin(), yy.end(), 1) - yy.begin();
if (ans == last) {
ans = -1;
}
}
} else {
int flag = 0;
for (int k = 0; k < 3; ++k) {
if (yy[k] > 0) {
flag |= 1 << k;
}
}
switch (flag) {
case 0b001: case 0b011: ans = 0; break;
case 0b010: case 0b110: ans = 1; break;
case 0b100: case 0b101: ans = 2; break;
default: assert(false);
}
}
if (ans != -1) {
last = ans;
}
return ans;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |