# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
503599 | snasibov05 | Mechanical Doll (IOI18_doll) | C++14 | 48 ms | 8348 KiB |
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 <queue>
using namespace std;
void create_circuit(int m, vector<int> a) {
int n = a.size();
vector<vector<int>> to(m+1);
to[0].push_back(a[0]);
to[a[n-1]].push_back(0);
for (int i = 0; i < n-1; ++i){
to[a[i]].push_back(a[i+1]);
}
vector<int> x, y;
vector<bool> state;
state.push_back(true);
x.push_back(0); y.push_back(0);
int cur = -1;
vector<int> c(m+1);
for (int i = 0; i <= m; ++i){
int k = 0, b = 1;
while (to[i].size() > b) b *= 2, k++;
if (k == 0){
if (to[i].empty()) c[i] = 0;
else c[i] = to[i][0];
continue;
}
int src = cur;
int mx = cur - b + 2;
c[i] = cur--;
queue<int> q;
q.push(cur+1);
while (!q.empty()){
state.push_back(true);
q.pop();
if (cur < mx) {
x.push_back(0);
y.push_back(0);
continue;
}
x.push_back(cur--);
y.push_back(cur--);
q.push(x.back());
q.push(y.back());
}
int rem = b - (int)to[i].size();
for (int j = 0; j < to[i].size() - rem; ++j){
int pos = src;
for (int l = 0; l < b-1; ++l) {
if (state[-pos]) {
state[-pos] = false;
pos = x[-pos];
} else{
state[-pos] = true;
pos = y[-pos];
}
}
if (state[-pos]) {
state[-pos] = false;
x[-pos] = to[i][j];
} else{
state[-pos] = true;
y[-pos] = to[i][j];
}
}
for (int j = to[i].size() - rem; j < to[i].size(); ++j){
int pos = src;
for (int l = 0; l < b-1; ++l) {
if (state[-pos]) {
state[-pos] = false;
pos = x[-pos];
} else{
state[-pos] = true;
pos = y[-pos];
}
}
if (state[-pos]) {
state[-pos] = false;
x[-pos] = src;
} else{
state[-pos] = true;
y[-pos] = src;
}
pos = src;
for (int l = 0; l < b-1; ++l) {
if (state[-pos]) {
state[-pos] = false;
pos = x[-pos];
} else{
state[-pos] = true;
pos = y[-pos];
}
}
if (state[-pos]) {
state[-pos] = false;
x[-pos] = to[i][j];
} else{
state[-pos] = true;
y[-pos] = to[i][j];
}
}
}
answer(c, x, y);
}
Compilation message (stderr)
# | 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... |