#include <iostream>
#include <vector>
#include <queue>
#include "doll.h"
using namespace std;
#define loop(X, N) for (int X = 0; X < (N); X++)
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
int rev(int n, int numBits) {
int out = 0;
for (int i = 0; i < numBits; i++) {
if (n & (1 << i))
out |= 1 << (numBits - 1 - i);
}
return out;
}
void create_circuit(int m, vi a) {
vi c; //exits
vi x, y;
int s = 0;
int n = a.size();
vvi nextStates(m);
for (int i = 0; i < n - 1; i++)
nextStates[a[i]].push_back(a[i + 1] + 1);
nextStates[a[n - 1]].push_back(0);
c.push_back(a[0] + 1);
for (int i = 0; i < m; i++) {
int pow = 1;
while (pow < nextStates[i].size())
pow *= 2;
if (pow == 1) {
c.push_back(nextStates[i][0]);
continue;
}
vi exits(pow);
for (int j = 0; j < nextStates[i].size() - 1; j++)
exits[rev(j, pow)] = nextStates[i][j];
for (int j = nextStates[i].size(); j < pow - 1; j++)
exits[rev(j, pow)] = -rev(j + 1, pow);
exits[rev(pow - 1, pow)] = nextStates[i].back();
for (int j = 1; j < pow / 2; j++) {
x.push_back(-(s + 2 * j));
y.push_back(-(s + 2 * j + 1));
}
for (int j = 0; j < pow / 2; j++) {
x.push_back(exits[j * 2]);
y.push_back(exits[j * 2 + 1]);
}
c.push_back(-s - 1);
s += pow - 1;
}
answer(c, x, y);
}
// int main() {
// create_circuit(2, {0, 1});
// return 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... |