# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
503600 | snasibov05 | Mechanical Doll (IOI18_doll) | C++14 | 63 ms | 7724 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;
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 < k-1; ++l) {
if (state[-pos-1]) {
state[-pos-1] = false;
pos = x[-pos-1];
} else{
state[-pos-1] = true;
pos = y[-pos-1];
}
}
if (state[-pos-1]) {
state[-pos-1] = false;
x[-pos-1] = to[i][j];
} else{
state[-pos-1] = true;
y[-pos-1] = to[i][j];
}
}
for (int j = to[i].size() - rem; j < to[i].size(); ++j){
int pos = src;
for (int l = 0; l < k-1; ++l) {
if (state[-pos-1]) {
state[-pos-1] = false;
pos = x[-pos-1];
} else{
state[-pos-1] = true;
pos = y[-pos-1];
}
}
if (state[-pos-1]) {
state[-pos-1] = false;
x[-pos-1] = src;
} else{
state[-pos-1] = true;
y[-pos-1] = src;
}
pos = src;
for (int l = 0; l < k-1; ++l) {
if (state[-pos-1]) {
state[-pos-1] = false;
pos = x[-pos-1];
} else{
state[-pos-1] = true;
pos = y[-pos-1];
}
}
if (state[-pos-1]) {
state[-pos-1] = false;
x[-pos-1] = to[i][j];
} else{
state[-pos-1] = true;
y[-pos-1] = 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... |