#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vii = vector<ii>;
const ll MOD = 998244353;
const int INF = 1e9+9;
const int MAXN = 1100006;
#include "doll.h"
int sm[MAXN], add[MAXN], nxt[MAXN];
vi gr[MAXN];
vi C, X, Y;
void create_circuit(int M, vector<int> A) {
for (int i = 1; i < (int) A.size(); ++i) {
gr[A[i-1]].push_back(A[i]);
}
gr[A.back()].push_back(0);
C.resize(M+1);
C[0] = A[0];
for (int i = 1; i <= M; ++i) {
if (gr[i].empty()) {
C[i] = 0;
continue;
}
if (gr[i].size() == 1) {
C[i] = gr[i][0];
continue;
}
int n = 2;
while (n < (int)gr[i].size())
n<<=1;
int extra = n-(int)gr[i].size();
sm[1] = 0;
add[1] = 1;
for (int j = 1; j < n; ++j) {
sm[j<<1] = sm[j];
sm[j<<1|1] = sm[j]+add[j];
add[j<<1] = add[j<<1|1] = add[j]<<1;
}
for (int j = 0, erased = 0; j < n; ++j) {
if (sm[n+j] < extra) {
erased++;
} else {
nxt[sm[n+j]] = gr[i][j-erased];
}
}
int fSw = X.size(); // first new switch
C[i] = -fSw-1;
sm[fSw] = 0;
add[fSw] = n>>1;
X.emplace_back(), Y.emplace_back();
for (int s = fSw; s < (int) X.size(); ++s) {
if (add[s] == 1) {
X[s] = sm[s] < extra? -fSw-1 : nxt[sm[s]];
Y[s] = nxt[sm[s]+1];
continue;
}
if (sm[s]+add[s] <= extra) {
X[s] = -fSw-1;
} else {
X[s] = -X.size()-1;
sm[X.size()] = sm[s];
add[X.size()] = add[s]>>1;
X.emplace_back(), Y.emplace_back();
}
Y[s] = -X.size()-1;
sm[X.size()] = sm[s]+add[s];
add[X.size()] = add[s]>>1;
X.emplace_back(), Y.emplace_back();
}
}
for (int i = 0; i <= M; ++i) {
cerr << C[i] << ' ';
}
cerr << endl;
for (int i = 0; i < (int) X.size(); ++i) {
cerr << X[i] << ' ' << Y[i] << endl;
}
answer(C, X, Y);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
26060 KB |
Output is correct |
2 |
Correct |
377 ms |
30328 KB |
Output is correct |
3 |
Correct |
319 ms |
29740 KB |
Output is correct |
4 |
Correct |
20 ms |
26148 KB |
Output is correct |
5 |
Correct |
332 ms |
27432 KB |
Output is correct |
6 |
Correct |
384 ms |
31704 KB |
Output is correct |
7 |
Correct |
18 ms |
26100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
26060 KB |
Output is correct |
2 |
Correct |
377 ms |
30328 KB |
Output is correct |
3 |
Correct |
319 ms |
29740 KB |
Output is correct |
4 |
Correct |
20 ms |
26148 KB |
Output is correct |
5 |
Correct |
332 ms |
27432 KB |
Output is correct |
6 |
Correct |
384 ms |
31704 KB |
Output is correct |
7 |
Correct |
18 ms |
26100 KB |
Output is correct |
8 |
Correct |
722 ms |
33516 KB |
Output is correct |
9 |
Correct |
688 ms |
33560 KB |
Output is correct |
10 |
Execution timed out |
1086 ms |
37148 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
26060 KB |
Output is correct |
2 |
Correct |
377 ms |
30328 KB |
Output is correct |
3 |
Correct |
319 ms |
29740 KB |
Output is correct |
4 |
Correct |
20 ms |
26148 KB |
Output is correct |
5 |
Correct |
332 ms |
27432 KB |
Output is correct |
6 |
Correct |
384 ms |
31704 KB |
Output is correct |
7 |
Correct |
18 ms |
26100 KB |
Output is correct |
8 |
Correct |
722 ms |
33516 KB |
Output is correct |
9 |
Correct |
688 ms |
33560 KB |
Output is correct |
10 |
Execution timed out |
1086 ms |
37148 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
26152 KB |
Output is correct |
2 |
Correct |
20 ms |
26144 KB |
Output is correct |
3 |
Correct |
25 ms |
26104 KB |
Output is correct |
4 |
Correct |
22 ms |
26060 KB |
Output is correct |
5 |
Correct |
17 ms |
26060 KB |
Output is correct |
6 |
Correct |
24 ms |
26048 KB |
Output is correct |
7 |
Correct |
19 ms |
26160 KB |
Output is correct |
8 |
Correct |
22 ms |
26144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
26072 KB |
Output is correct |
2 |
Correct |
886 ms |
34848 KB |
Output is correct |
3 |
Correct |
942 ms |
37232 KB |
Output is correct |
4 |
Execution timed out |
1082 ms |
36884 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
26072 KB |
Output is correct |
2 |
Correct |
886 ms |
34848 KB |
Output is correct |
3 |
Correct |
942 ms |
37232 KB |
Output is correct |
4 |
Execution timed out |
1082 ms |
36884 KB |
Time limit exceeded |