/*input
*/
#include <bits/stdc++.h>
#include "doll.h"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef vector<pi> vpi;
typedef vector<vpi> vpii;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<pd> vpd;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef std::string str;
typedef std::vector<str> vs;
#define x first
#define y second
#define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n"
const int MOD = 1000000007;
const ll INF = std::numeric_limits<ll>::max();
const int MX = 100101;
const ld PI = 3.14159265358979323846264338327950288419716939937510582097494L;
template<typename T>
pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x + b.x, a.y + b.y); }
template<typename T>
pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x - b.x, a.y - b.y); }
template<typename T>
T operator*(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.x + a.y * b.y); }
template<typename T>
T operator^(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.y - a.y * b.x); }
template<typename T>
void print(vector<T> vec, string name = "") {
cout << name;
for (auto u : vec)
cout << u << ' ';
cout << '\n';
}
vi C;
vi X, Y;
int S = 0;
vii iseina;
int N;
int truksta;
int n;
int pradSw;
int maxLvl;
vpi place;
int nxtS() {
X.push_back(0);
Y.push_back(0);
S++;
// printf("s = %d, grazinu = %d\n", S, -S);
return -S;
}
void make(int sw, int currLvl, int pos) {
int manoMedyElm = (1 << (maxLvl - currLvl + 1));
// printf("sw = %d, pradsW = %d, manoMedyElm = %d, truksta = %d\n", sw, pradSw, manoMedyElm, truksta);
if (manoMedyElm <= truksta) {
X[sw] = Y[sw] = pradSw;
truksta -= manoMedyElm;
return;
}
if (currLvl == maxLvl) {
if (!truksta) place[pos] = {sw, 0};
else {
X[sw] = pradSw;
truksta--;
}
pos |= (1 << currLvl);
place[pos] = {sw, 1};
} else {
int ns = nxtS();
X[sw] = ns;
ns = nxtS();
Y[sw] = ns;
// print(X, "X: ");
// print(Y, "Y: ");
// printf("sw = %d, x y = %d %d, S = %d\n", sw, X[sw], Y[sw], S);
make(-X[sw], currLvl + 1, pos);
make(-Y[sw], currLvl + 1, pos | (1 << currLvl));
// printf("sz = %d, ~panaudojau = %d\n", manoMedyElm, S - pr);
}
}
void daryk(int m) {
int sz = (int)iseina[m].size();
n = (1 << (int)ceil(log2(sz)));
maxLvl = log2(n);
maxLvl--;
truksta = n - sz;
// printf("sz = %d, n = %d, mxlvl = %d,truksta = %d\n", sz, n, maxLvl, truksta);
place = vpi(n, pi(MOD, MOD));
int pr = S;
int cs = nxtS();
C[m] = cs;
pradSw = C[m];
make(-C[m], 0, 0);
// printf("sz = %d, ~panaudojau = %d\n", sz, S - pr);
// printf("m = %d, sz = %d, n = %d, place:\n", m, sz, n);
// for (auto u : place)
// printf("%d %d\n", u.x, u.y);
// printf("\n");
int j = 0;
for (int i = 0; i < sz; ++i)
{
while (j < n and place[j].x == MOD) j++;
assert(j < n);
int h = place[j].x;
// printf("i = %d, iseina = %d, h = %d\n", i, iseina[m][i], h);
if (place[j].y) Y[h] = iseina[m][i];
else X[h] = iseina[m][i];
j++;
}
}
void create_circuit(int M, vi A) {
N = A.size();
C = vi(M + 1);
iseina = vii(M + 1);
A.emplace_back(0);
C[0] = A[0];
for (int i = 0; i < N; ++i)
iseina[A[i]].emplace_back(A[i + 1]);
X.emplace_back(0);
Y.emplace_back(0);
for (int i = 1; i <= M; ++i)
{
if (iseina[i].empty()) C[i] = 0;
else if (iseina[i].size() == 1) C[i] = iseina[i][0];
else daryk(i);
}
X.erase(X.begin());
Y.erase(Y.begin());
// printf("S = %d\n", S);
// print(C, "C: ");
// for (int i = 0; i < S; ++i) printf("%d ", X[i]); printf("\n");
// for (int i = 0; i < S; ++i) printf("%d ", Y[i]); printf("\n");
answer(C, X, Y);
}
Compilation message
doll.cpp: In function 'void daryk(int)':
doll.cpp:122:6: warning: unused variable 'pr' [-Wunused-variable]
122 | int pr = S;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
37 ms |
6384 KB |
Output is correct |
3 |
Correct |
31 ms |
5240 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
13 ms |
3788 KB |
Output is correct |
6 |
Correct |
40 ms |
7860 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
37 ms |
6384 KB |
Output is correct |
3 |
Correct |
31 ms |
5240 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
13 ms |
3788 KB |
Output is correct |
6 |
Correct |
40 ms |
7860 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
74 ms |
8000 KB |
Output is correct |
9 |
Correct |
83 ms |
9148 KB |
Output is correct |
10 |
Correct |
101 ms |
12324 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
2 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
37 ms |
6384 KB |
Output is correct |
3 |
Correct |
31 ms |
5240 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
13 ms |
3788 KB |
Output is correct |
6 |
Correct |
40 ms |
7860 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
74 ms |
8000 KB |
Output is correct |
9 |
Correct |
83 ms |
9148 KB |
Output is correct |
10 |
Correct |
101 ms |
12324 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
2 ms |
204 KB |
Output is correct |
14 |
Correct |
139 ms |
13380 KB |
Output is correct |
15 |
Correct |
60 ms |
6848 KB |
Output is correct |
16 |
Correct |
90 ms |
10172 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
116 ms |
12324 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1 ms |
204 KB |
Output is partially correct |
2 |
Correct |
65 ms |
7364 KB |
Output is correct |
3 |
Partially correct |
48 ms |
7560 KB |
Output is partially correct |
4 |
Correct |
74 ms |
10384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
1 ms |
204 KB |
Output is partially correct |
2 |
Correct |
65 ms |
7364 KB |
Output is correct |
3 |
Partially correct |
48 ms |
7560 KB |
Output is partially correct |
4 |
Correct |
74 ms |
10384 KB |
Output is correct |
5 |
Partially correct |
129 ms |
14320 KB |
Output is partially correct |
6 |
Partially correct |
128 ms |
13756 KB |
Output is partially correct |
7 |
Partially correct |
117 ms |
14008 KB |
Output is partially correct |
8 |
Partially correct |
122 ms |
12524 KB |
Output is partially correct |
9 |
Partially correct |
74 ms |
6968 KB |
Output is partially correct |
10 |
Partially correct |
99 ms |
11804 KB |
Output is partially correct |
11 |
Partially correct |
76 ms |
10036 KB |
Output is partially correct |
12 |
Partially correct |
53 ms |
5896 KB |
Output is partially correct |
13 |
Partially correct |
72 ms |
8192 KB |
Output is partially correct |
14 |
Partially correct |
77 ms |
8404 KB |
Output is partially correct |
15 |
Partially correct |
100 ms |
8836 KB |
Output is partially correct |
16 |
Partially correct |
3 ms |
460 KB |
Output is partially correct |
17 |
Partially correct |
51 ms |
6564 KB |
Output is partially correct |
18 |
Partially correct |
66 ms |
6452 KB |
Output is partially correct |
19 |
Partially correct |
60 ms |
5584 KB |
Output is partially correct |
20 |
Partially correct |
85 ms |
9748 KB |
Output is partially correct |
21 |
Partially correct |
78 ms |
9088 KB |
Output is partially correct |
22 |
Partially correct |
84 ms |
9072 KB |
Output is partially correct |