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 "doll.h"
#include <bits/stdc++.h>
using namespace std;
struct Graph {
int S = 1;
int N = 200000;
vector<int> X, Y, turn;
void build(int node, int level, int first_turn) {
if ((1 << level) > N) {
turn[node] = first_turn;
return;
}
X[node] = 2 * node;
Y[node] = 2 * node + 1;
build(X[node], level + 1, first_turn);
build(Y[node], level + 1, first_turn + (1 << level));
X[node] *= -1;
Y[node] *= -1;
}
void build() {
while (S < N) {
S <<= 1;
}
X.resize(S + 1);
Y.resize(S + 1);
turn = vector<int>(2 * S, -1);
build(1, 0, 0);
}
};
bool simulate(int M, vector<int> A, vector<int> IC, vector<int> IX,
vector<int> IY) {
int S = IX.size();
int N = A.size();
for (int i = 0; i <= M; ++i) {
if (!(-S <= IC[i] && IC[i] <= M)) {
return false;
}
}
for (int j = 1; j <= S; ++j) {
if (!(-S <= IX[j - 1] && IX[j - 1] <= M)) {
return false;
}
if (!(-S <= IY[j - 1] && IY[j - 1] <= M)) {
return false;
}
}
int P = 0;
std::vector<bool> state(S + 1, false);
int pos = IC[0];
int k = 0;
for (;;) {
if (pos < 0) {
state[-pos] = !state[-pos];
pos = state[-pos] ? IX[-(1 + pos)] : IY[-(1 + pos)];
} else {
if (pos == 0) {
break;
}
if (k >= N) {
return false;
}
if (pos != A[k++]) {
return false;
}
pos = IC[pos];
}
}
if (k != N) {
return false;
}
for (int j = 1; j <= S; ++j) {
if (state[j]) {
return false;
}
}
return true;
}
void create_circuit(int M, std::vector<int> A) {
assert(false);
Graph graph;
graph.build();
vector<int> C(M + 1);
for (int& x : C) {
x = -1;
}
for (int i = graph.S / 2; i < graph.S; ++i) {
if (graph.turn[-graph.X[i]] < A.size()) {
graph.X[i] = A[graph.turn[-graph.X[i]]];
} else {
graph.X[i] = -1;
}
if (graph.turn[-graph.Y[i]] < A.size()) {
graph.Y[i] = A[graph.turn[-graph.Y[i]]];
} else {
graph.Y[i] = -1;
}
}
graph.Y[graph.S - 1] = 0;
graph.X.erase(graph.X.begin());
graph.Y.erase(graph.Y.begin());
assert(simulate(M, A, C, graph.X, graph.Y));
answer(C, graph.X, graph.Y);
}
Compilation message (stderr)
doll.cpp: In function 'bool simulate(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
doll.cpp:55:7: warning: unused variable 'P' [-Wunused-variable]
55 | int P = 0;
| ^
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:99:33: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
99 | if (graph.turn[-graph.X[i]] < A.size()) {
doll.cpp:104:33: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
104 | if (graph.turn[-graph.Y[i]] < A.size()) {
# | 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... |