#include "doll.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
using namespace std;
struct xyswitch {
int x, y;
bool gox = true;
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(int m, int filler, int base_switch) {
int s1 = 0, s2 = 0;
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++; }
else s2++;
}
else {
s2++;
}
}
xyswitches.push_back(xyswitch());
int sn = xyswitches.size() - 1;
if (s1 == 0) { xyswitches[sn].x = base_switch; }
else if (s1 == 1) {
xyswitches[sn].x = 0;
}
else {
xyswitches[sn].x = -((int)xyswitches.size() + 1);
make_switches(s1, f1, base_switch);
}
if (s2== 1) {
xyswitches[sn].y = 0;
}
else {
xyswitches[sn].y = -((int)xyswitches.size() + 1);
make_switches(s2, f2, base_switch);
}
}
void connect(int val, int swid)
{
xyswitch & sw = xyswitches[-(swid)-1];
if (sw.gox)
{
sw.gox = !sw.gox;
if (sw.x == 0) { sw.x = val; }
else { connect(val, sw.x); }
}
else
{
sw.gox = !sw.gox;
if (sw.y == 0) { sw.y = val; }
else { connect(val, sw.y); }
}
}
void create_circuit(int M, std::vector<int> A) {
int n = A.size();
vector<vector<int>> repetitions;
repetitions.resize(M+1);
vector<int> c(M+1,0);
for (int i = 0; i < n - 1; i++) {
repetitions[A[i]].push_back(A[i + 1]);
}
repetitions[A[n - 1]].push_back(0);
for (int i = 1; i <= M; i++)
{
int m = repetitions[i].size(), mxtwo = 1;
while (mxtwo < m) { mxtwo *= 2; }
if (m == 0) { continue; }
if (m == 1) {
c[i] = repetitions[i][0];
}
else {
c[i] = -(int)xyswitches.size() - 1;
make_switches(repetitions[i].size(), mxtwo - m, xyswitches.size() + 1);
for (int j = 0; j < repetitions[i].size(); j++) {
connect(repetitions[i][j], c[i]);
}
}
}
int s = xyswitches.size();
vector<int> x(s), y(s);
c[0] = A[0];
for (int i = 0; i < s; i++) {
x[i] = xyswitches[i].x;
y[i] = xyswitches[i].y;
}
answer(c, x, y);
}
Compilation message
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:90:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
90 | for (int j = 0; j < repetitions[i].size(); j++) {
| ~~^~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
18 ms |
6776 KB |
Output is correct |
3 |
Correct |
14 ms |
5724 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
9 ms |
3932 KB |
Output is correct |
6 |
Correct |
22 ms |
8532 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
18 ms |
6776 KB |
Output is correct |
3 |
Correct |
14 ms |
5724 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
9 ms |
3932 KB |
Output is correct |
6 |
Correct |
22 ms |
8532 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
30 ms |
8988 KB |
Output is correct |
9 |
Correct |
30 ms |
10196 KB |
Output is correct |
10 |
Correct |
44 ms |
13512 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
18 ms |
6776 KB |
Output is correct |
3 |
Correct |
14 ms |
5724 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
9 ms |
3932 KB |
Output is correct |
6 |
Correct |
22 ms |
8532 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
30 ms |
8988 KB |
Output is correct |
9 |
Correct |
30 ms |
10196 KB |
Output is correct |
10 |
Correct |
44 ms |
13512 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Runtime error |
27 ms |
13132 KB |
Execution killed with signal 6 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1040 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1040 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |