#include <bits/stdc++.h>
#include "doll.h"
#define ll long long
#define pb push_back
#define ff first
#define ss second
using namespace std;
int n;
int currentSwitch = 1;
vector<int>goes[100002];
vector<int>c, x, y;
vector<ll>potencias2;
bool isPot(ll k){
while(k > 1){
if(k % 2 == 1)return false;
k/=2;
}
return true;
}
int principio, puntero;
int generar(ll vec, ll desde, ll cada, ll cuantosHay, bool up){
//cout << "generando " << vec << " desde " << desde << " " << cada << "hay " << cuantosHay << endl;
ll tam = goes[vec].size()-desde;
ll cuantosReal = (tam + cada-1)/cada;
if(cuantosReal == 1 and cuantosHay == 1){
return goes[vec][desde];
}
if(cuantosReal <= 0 and cuantosHay == 1){
if(!up){
return principio;
}else{
return INT_MAX;
}
}
x.pb(0);
y.pb(0);
int estoy = currentSwitch ++ ; // 1
x[estoy-1] = generar(vec, desde, cada * 2, cuantosHay/2, false);
y[estoy-1] = generar(vec, desde + cada, cada*2, cuantosHay/2, up);
if(y[estoy-1] == INT_MAX)puntero = estoy-1;
return (-estoy);
}
void create_circuit(int M, std::vector<int> A) {
n = A.size();
for(int i = 1 ; i < n ; i ++){
goes[A[i-1]].pb(A[i]);
}
int temp = 1;
while(temp < 2000000){
potencias2.pb(temp);
temp*= 2;
}
int ultimo = A.back();
//goes[A.back()].pb(0);
bool vis[M+1];
memset(vis,false, sizeof vis);
c.pb(A[0]);
vector<pair<int, int> > toRepair; // switch inicio, indice Y final
for(int i = 1 ; i <= M ; i ++)c.pb(0);
for(int i = 0 ; i < n ; i ++){
if(A[i] == ultimo)continue;
if(!vis[A[i]]){
vis[A[i]] = true;
principio = -currentSwitch;
ll nextPot = 1;
while(nextPot < goes[A[i]].size())nextPot*=2;
c[A[i]] = generar(A[i], 0, 1, nextPot, true);
if(!isPot(goes[A[i]].size())){
toRepair.pb({c[A[i]], puntero});
//cout << "ins " << c[A[i]] << " " << puntero << endl;
}
}
}
if(goes[ultimo].size() == 0){
if(toRepair.size() == 0){
c[ultimo] = 0;
answer(c, x, y);
return ;
}else{
c[ultimo] = toRepair.back().ff;
}
}else{
principio = -currentSwitch;
int nextPot = 1;
while(nextPot < goes[ultimo].size())nextPot*=2;
if(nextPot == goes[ultimo].size()){
c[ultimo] = generar(ultimo, 0, 1, nextPot*2, true);
toRepair.pb({c[ultimo], puntero});
}else {
c[ultimo] = generar(ultimo, 0, 1, nextPot, true);
toRepair.pb({c[ultimo], puntero});
}
}
for(int i = toRepair.size() -1 ; i > 0 ; i --){
//cout << "end " << toRepair[i].ss << " to " << toRepair[i-1].ff << endl;
y[toRepair[i].ss] = toRepair[i-1].ff;
}
y[toRepair[0].ss] = 0;
answer(c, x, y);
}
Compilation message
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:70:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | while(nextPot < goes[A[i]].size())nextPot*=2;
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~
doll.cpp:89:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
89 | while(nextPot < goes[ultimo].size())nextPot*=2;
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
doll.cpp:90:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
90 | if(nextPot == goes[ultimo].size()){
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
25 ms |
6632 KB |
Output is correct |
3 |
Correct |
19 ms |
6096 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
9 ms |
4044 KB |
Output is correct |
6 |
Correct |
25 ms |
7928 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
25 ms |
6632 KB |
Output is correct |
3 |
Correct |
19 ms |
6096 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
9 ms |
4044 KB |
Output is correct |
6 |
Correct |
25 ms |
7928 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
34 ms |
8792 KB |
Output is correct |
9 |
Correct |
34 ms |
8892 KB |
Output is correct |
10 |
Correct |
50 ms |
11328 KB |
Output is correct |
11 |
Correct |
1 ms |
2548 KB |
Output is correct |
12 |
Correct |
1 ms |
2644 KB |
Output is correct |
13 |
Correct |
1 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
25 ms |
6632 KB |
Output is correct |
3 |
Correct |
19 ms |
6096 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
9 ms |
4044 KB |
Output is correct |
6 |
Correct |
25 ms |
7928 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
34 ms |
8792 KB |
Output is correct |
9 |
Correct |
34 ms |
8892 KB |
Output is correct |
10 |
Correct |
50 ms |
11328 KB |
Output is correct |
11 |
Correct |
1 ms |
2548 KB |
Output is correct |
12 |
Correct |
1 ms |
2644 KB |
Output is correct |
13 |
Correct |
1 ms |
2644 KB |
Output is correct |
14 |
Correct |
65 ms |
12652 KB |
Output is correct |
15 |
Correct |
34 ms |
8488 KB |
Output is correct |
16 |
Correct |
52 ms |
11584 KB |
Output is correct |
17 |
Correct |
2 ms |
2644 KB |
Output is correct |
18 |
Correct |
1 ms |
2644 KB |
Output is correct |
19 |
Correct |
1 ms |
2652 KB |
Output is correct |
20 |
Correct |
68 ms |
13708 KB |
Output is correct |
21 |
Correct |
1 ms |
2644 KB |
Output is correct |
22 |
Correct |
1 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
2 ms |
2644 KB |
Output is partially correct |
2 |
Correct |
31 ms |
8516 KB |
Output is correct |
3 |
Partially correct |
51 ms |
12180 KB |
Output is partially correct |
4 |
Partially correct |
61 ms |
12688 KB |
Output is partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
2 ms |
2644 KB |
Output is partially correct |
2 |
Correct |
31 ms |
8516 KB |
Output is correct |
3 |
Partially correct |
51 ms |
12180 KB |
Output is partially correct |
4 |
Partially correct |
61 ms |
12688 KB |
Output is partially correct |
5 |
Partially correct |
78 ms |
16752 KB |
Output is partially correct |
6 |
Partially correct |
94 ms |
17452 KB |
Output is partially correct |
7 |
Partially correct |
79 ms |
17192 KB |
Output is partially correct |
8 |
Partially correct |
82 ms |
17888 KB |
Output is partially correct |
9 |
Partially correct |
52 ms |
12452 KB |
Output is partially correct |
10 |
Partially correct |
96 ms |
17956 KB |
Output is partially correct |
11 |
Partially correct |
101 ms |
18504 KB |
Output is partially correct |
12 |
Partially correct |
53 ms |
12980 KB |
Output is partially correct |
13 |
Partially correct |
53 ms |
12292 KB |
Output is partially correct |
14 |
Partially correct |
52 ms |
11964 KB |
Output is partially correct |
15 |
Partially correct |
52 ms |
11708 KB |
Output is partially correct |
16 |
Partially correct |
3 ms |
2900 KB |
Output is partially correct |
17 |
Partially correct |
44 ms |
10736 KB |
Output is partially correct |
18 |
Partially correct |
44 ms |
10820 KB |
Output is partially correct |
19 |
Partially correct |
47 ms |
11404 KB |
Output is partially correct |
20 |
Partially correct |
63 ms |
14020 KB |
Output is partially correct |
21 |
Partially correct |
71 ms |
16396 KB |
Output is partially correct |
22 |
Partially correct |
60 ms |
13280 KB |
Output is partially correct |