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 <iostream>
#include <set>
#include <vector>
#include <queue>
#include <assert.h>
using namespace std;
#define pii pair<int, int>
vector<int> Mark(int n, int m, int a, int b, vector<int> u, vector<int> v) {
vector<vector<pii>> 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});
if (a == 2) {
vector<int> color(m, -1), dist(n, -1), lp(n), llp(n);
for (int i = 0; i < n; ++i) lp[i] = i, llp[i] = i;
queue<int> q; q.push(0), dist[0] = 0;
set<int> heads;
while (q.size()) {
int v = q.front(); q.pop();
int label = dist[v] % 2;
for (const auto& [u, i] : adj[v]) {
if (color[i] >= 0) {
if (adj[v].size() == 2) {
lp[v] = lp[u];
if (lp[u] == u) heads.insert(v);
else llp[v] = llp[u];
}
continue;
}
color[i] = label;
q.push(u), dist[u] = dist[v] + 1;
}
}
for (int i = 0; i < m; ++i) {
//cout << u[i] << ' ' << v[i] << ' ' << color[i] << endl;
}
vector<int> pat = {1, 1, 0, 0, 1, 0};
vector<int> shifts(n);
for (int p : heads) {
int cur = p;
while (true) {
bool can = false;
for (const auto& [u, i] : adj[cur]) {
if (dist[u] > dist[cur] && adj[u].size() == 2) can = true, cur = u;
}
if (!can) break;
}
int v1 = dist[lp[p]] % 2, v2 = dist[cur] % 2;
int dd = dist[cur] - dist[lp[p]];
int shift = 0;
if (dd % 6 == 0) shift = v1 ? 0 : 2;
else if (dd % 6 == 1) shift = v1 ? 1 : 3;
else if (dd % 6 == 2) shift = v1 ? 4 : 3;
else if (dd % 6 == 3) shift = v1 ? 0 : 3;
else if (dd % 6 == 4) shift = v1 ? 0 : 5;
else shift = v1 ? 0 : 5;
shifts[p] = shift;
}
for (int v = 1; v < n; ++v) {
if (adj[v].size() != 2) continue;
int p = lp[v];
int shift = shifts[llp[v]];
for (const auto& [u, i] : adj[v]) {
if (dist[u] > dist[v]) {
color[i] = pat[(dist[v] - dist[p] + shift) % 6];
}
}
}
for (int i = 0; i < m; ++i) {
//cout << u[i] << ' ' << v[i] << ' ' << color[i] << endl;
}
return color;
}
vector<int> color(m, -1), dist(n, -1);
queue<int> q; q.push(0), dist[0] = 0;
while (q.size()) {
int v = q.front(); q.pop();
int label = dist[v] % 3;
for (const auto& [u, i] : adj[v]) {
if (color[i] >= 0) continue;
color[i] = label;
if (dist[u] < 0) q.push(u), dist[u] = dist[v] + 1;
}
}
for (int num : color) assert(num >= 0 && num < 3);
return color;
}
#include "Catherine.h"
#include <iostream>
#include <vector>
#include <assert.h>
using namespace std;
int a;
void Init(int _a, int _b) {
a = _a;
}
int prv = -1;
bool start = false;
vector<int> seen;
bool forwards() {
assert(seen.size() == 5);
vector<int> f1 = {0, 1, 0, 0, 1};
vector<int> f2 = {1, 0, 0, 1, 1};
vector<int> f3 = {0, 0, 1, 1, 0};
vector<int> f4 = {0, 1, 1, 0, 1};
vector<int> f5 = {1, 1, 0, 1, 0};
vector<int> f6 = {1, 0, 1, 0, 0};
return seen == f1 || seen == f2 || seen == f3 || seen == f4 || seen == f5 || seen == f6;
}
int Move(vector<int> y) {
vector<int> copy = y;
y.clear();
for (int i = 0; i < copy.size(); ++i)
for (int j = 0; j < copy[i]; ++j) y.push_back(i);
if (a == 2) {
if (start) {
if (y.size() == 1) {
return prv = y[0];
}
for (int i = 0; i < y.size(); ++i) {
if (y[i] != prv) {
return prv = y[i];
}
}
// Shouldn't ever happen:
//cout << copy[0] << ' ' << copy[1] << endl;
assert(0);
return 0;
} else {
if (y.size() > 1) {
int sum = 0;
for (int num : y) sum += num;
if (sum == 0 || sum == y.size()) {
start = true;
return -1;
}
if (prv == -1 && y.size() == 2) {
seen.push_back(y[0]), seen.push_back(y[1]);
return prv = y[1];
}
if (prv == -1) {
int find = sum == 1;
for (int i = 0; i < y.size(); ++i) {
if (y[i] == find) {
start = true;
return prv = y[i];
}
}
// Shouldn't ever happen:
assert(0);
return 0;
}
for (int i = 0; i < y.size(); ++i) {
if (y[i] != prv) {
start = true;
return prv = y[i];
}
}
// Shouldn't ever happen:
assert(0);
return 0;
} else {
if (y.size() == 0) {
start = true;
return -1;
}
seen.push_back(y[0]);
if (seen.size() < 5) {
return prv = y[0];
}
start = true;
if (forwards()) {
return prv = y[0];
}
return -1;
}
// Shouldn't ever happen:
assert(0);
return 0;
}
}
vector<int> count(3);
for (int num : y) ++count[num];
if (max(count[0], max(count[1], count[2])) == y.size()) return y[0];
return !count[0] ? 1 : (!count[1] ? 2 : 0);
}
Compilation message (stderr)
Anthony.cpp: In function 'std::vector<int> Mark(int, int, int, int, std::vector<int>, std::vector<int>)':
Anthony.cpp:22:24: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
22 | for (const auto& [u, i] : adj[v]) {
| ^
Anthony.cpp:44:26: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
44 | for (const auto& [u, i] : adj[cur]) {
| ^
Anthony.cpp:49:33: warning: unused variable 'v2' [-Wunused-variable]
49 | int v1 = dist[lp[p]] % 2, v2 = dist[cur] % 2;
| ^~
Anthony.cpp:64:24: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
64 | for (const auto& [u, i] : adj[v]) {
| ^
Anthony.cpp:80:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
80 | for (const auto& [u, i] : adj[v]) {
| ^
Catherine.cpp: In function 'int Move(std::vector<int>)':
Catherine.cpp:31:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for (int i = 0; i < copy.size(); ++i)
| ~~^~~~~~~~~~~~~
Catherine.cpp:38:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for (int i = 0; i < y.size(); ++i) {
| ~~^~~~~~~~~~
Catherine.cpp:51:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | if (sum == 0 || sum == y.size()) {
| ~~~~^~~~~~~~~~~
Catherine.cpp:61:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for (int i = 0; i < y.size(); ++i) {
| ~~^~~~~~~~~~
Catherine.cpp:71:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | for (int i = 0; i < y.size(); ++i) {
| ~~^~~~~~~~~~
Catherine.cpp:102:46: warning: comparison of integer expressions of different signedness: 'const int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
102 | if (max(count[0], max(count[1], count[2])) == y.size()) return y[0];
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
# | 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... |