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 <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
using namespace std;
struct xyswitch {
int x, y;
xyswitch() {}
xyswitch(int x, int y) { this->x = x; this->y = y; }
};
void answer(vector<int> C, vector<int> X, vector<int> Y);
vector<xyswitch> xyswitches;
void make_switches(vector<int>& connected, int filler, int base_switch) {
vector<int> s1, s2;
int m = connected.size();
int f1 = min(filler, (m+filler)/2), f2 = filler - f1;
for (int i = 0; i < m; i++) {
if (i % 2 == 0) {
if (i/2 >= f1) { s1.push_back(connected[i]); }
else s2.push_back(connected[i]);
} else {
s2.push_back(connected[i]);
}
}
int x, y;
xyswitches.push_back(xyswitch());
int sn = xyswitches.size() - 1;
if (s1.size() == 0) { xyswitches[sn].x = base_switch; }
else if (s1.size() == 1) {
xyswitches[sn].x = s1[0];
} else {
xyswitches[sn].x = -((int)xyswitches.size() + 1);
make_switches(s1, f1, base_switch);
}
if (s2.size() == 1) {
xyswitches[sn].y = s2[0];
} else {
xyswitches[sn].y = -((int)xyswitches.size()+1);
make_switches(s2, f2, base_switch);
}
}
void create_circuit(int M, std::vector<int> A) {
int n = A.size();
unordered_map<int,int> visited;
for (int i = 0; i < n; i++) {
if (!visited.count(A[i])) {
visited[A[i]] = 0;
vector<int> connected;
connected.reserve(n-i);
for (int j = i; j < n; j++) {
if (A[j] == A[i]) {
(j == n - 1) ? connected.push_back(0) : connected.push_back(A[j + 1]);
}
}
int m = connected.size(), mxtwo = 1;
while (mxtwo < m) { mxtwo *= 2; }
if (m == 1) {
visited[A[i]] = connected[0];
} else {
visited[A[i]] = -(int)xyswitches.size()-1;
make_switches(connected, mxtwo - m, xyswitches.size()+1);
}
}
}
int s = xyswitches.size();
vector<int> c(M+1), x(s), y(s);
c[0] = A[0];
for (int i = 1; i < M+1;i++) {
if (visited.count(i)) { c[i] = visited[i]; }
else { c[i] = i; }
}
for (int i = 0; i < s; i++) {
x[i] = xyswitches[i].x;
y[i] = xyswitches[i].y;
}
answer(c, x, y);
}
Compilation message (stderr)
doll.cpp: In function 'void make_switches(std::vector<int>&, int, int)':
doll.cpp:27:9: warning: unused variable 'x' [-Wunused-variable]
27 | int x, y;
| ^
doll.cpp:27:12: warning: unused variable 'y' [-Wunused-variable]
27 | int x, y;
| ^
# | 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... |