#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ff first
#define ss second
ll ttt;
const ll INF=1e18;
const ll MOD=1e9+7;
const ll N=300007;
ll n,m,k;
ll lg2[N];
int cnt[N];
int val[N];
vector<int>vs[N];
int cc[N];
string dec_to_bin(int num, int len){
string s="";
for(int _=0;_<len;_++){
s+=num%2+'0';
num/=2;
}
return s;
}
void create_circuit(int M, std::vector<int> a) {
n = a.size();
m=M;
lg2[1]=0;
for(int i=2;i<N;i++){
lg2[i]=lg2[i/2]+1;
}
vector<int>uniq;
for(int x:a){
if(cnt[x]==0)uniq.push_back(x);
cnt[x]++;
}
int cur=-1;
for(int x:uniq){
val[x]=lg2[cnt[x]-1];
vs[x].push_back(0);
if(cnt[x]>1){
for(int _=0;_<(1<<(val[x]+1))-1;_++){
vs[x].push_back(cur);
cur--;
}
}
}
vector<int>C(M+1),X(-cur-1,-1),Y(-cur-1,-1);
C[0]=a[0];
for(int x:uniq){
if(cnt[x]>1)C[x]=vs[x][1];
for(int i=1;i<vs[x].size()/2;i++){
X[-vs[x][i]-1]=vs[x][2*i];
Y[-vs[x][i]-1]=vs[x][2*i+1];
}
}
a.push_back(0);
for(int i=0;i<a.size()-1;i++){
int x=a[i];
if(cnt[x]==1){
C[x]=a[i+1];
}
else{
if(cc[x]!=cnt[x]-1){
string s=dec_to_bin(cc[x],val[x]+1);
int ind=1;
for(int j=0;j+1<s.size();j++){
ind*=2;
if(s[j]=='1')ind+=1;
}
if(s.back()=='0'){
X[-vs[x][ind]-1]=a[i+1];
}
else{
Y[-vs[x][ind]-1]=a[i+1];
}
}
else{
for(int i=1;i<vs[x].size();i++){
if(X[-vs[x][i]-1]==-1){
X[-vs[x][i]-1]=vs[x][1];
}
if(Y[-vs[x][i]-1]==-1){
Y[-vs[x][i]-1]=vs[x][1];
}
}
Y[-vs[x].back()-1]=a[i+1];
}
cc[x]++;
}
}
answer(C,X,Y);
}
Compilation message
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:60:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for(int i=1;i<vs[x].size()/2;i++){
| ~^~~~~~~~~~~~~~~
doll.cpp:66:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for(int i=0;i<a.size()-1;i++){
| ~^~~~~~~~~~~
doll.cpp:75:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
75 | for(int j=0;j+1<s.size();j++){
| ~~~^~~~~~~~~
doll.cpp:87:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
87 | for(int i=1;i<vs[x].size();i++){
| ~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9644 KB |
Output is correct |
2 |
Correct |
24 ms |
14896 KB |
Output is correct |
3 |
Correct |
21 ms |
14236 KB |
Output is correct |
4 |
Correct |
5 ms |
9664 KB |
Output is correct |
5 |
Correct |
15 ms |
10944 KB |
Output is correct |
6 |
Correct |
29 ms |
16592 KB |
Output is correct |
7 |
Correct |
5 ms |
9684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9644 KB |
Output is correct |
2 |
Correct |
24 ms |
14896 KB |
Output is correct |
3 |
Correct |
21 ms |
14236 KB |
Output is correct |
4 |
Correct |
5 ms |
9664 KB |
Output is correct |
5 |
Correct |
15 ms |
10944 KB |
Output is correct |
6 |
Correct |
29 ms |
16592 KB |
Output is correct |
7 |
Correct |
5 ms |
9684 KB |
Output is correct |
8 |
Correct |
39 ms |
17484 KB |
Output is correct |
9 |
Correct |
42 ms |
18024 KB |
Output is correct |
10 |
Correct |
58 ms |
20920 KB |
Output is correct |
11 |
Correct |
4 ms |
9684 KB |
Output is correct |
12 |
Correct |
4 ms |
9664 KB |
Output is correct |
13 |
Correct |
6 ms |
9780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9644 KB |
Output is correct |
2 |
Correct |
24 ms |
14896 KB |
Output is correct |
3 |
Correct |
21 ms |
14236 KB |
Output is correct |
4 |
Correct |
5 ms |
9664 KB |
Output is correct |
5 |
Correct |
15 ms |
10944 KB |
Output is correct |
6 |
Correct |
29 ms |
16592 KB |
Output is correct |
7 |
Correct |
5 ms |
9684 KB |
Output is correct |
8 |
Correct |
39 ms |
17484 KB |
Output is correct |
9 |
Correct |
42 ms |
18024 KB |
Output is correct |
10 |
Correct |
58 ms |
20920 KB |
Output is correct |
11 |
Correct |
4 ms |
9684 KB |
Output is correct |
12 |
Correct |
4 ms |
9664 KB |
Output is correct |
13 |
Correct |
6 ms |
9780 KB |
Output is correct |
14 |
Correct |
69 ms |
21556 KB |
Output is correct |
15 |
Correct |
40 ms |
15944 KB |
Output is correct |
16 |
Correct |
60 ms |
19176 KB |
Output is correct |
17 |
Correct |
5 ms |
9660 KB |
Output is correct |
18 |
Correct |
5 ms |
9684 KB |
Output is correct |
19 |
Correct |
5 ms |
9684 KB |
Output is correct |
20 |
Correct |
73 ms |
20832 KB |
Output is correct |
21 |
Correct |
5 ms |
9684 KB |
Output is correct |
22 |
Correct |
5 ms |
9684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
9684 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
5 ms |
9664 KB |
Output is partially correct |
2 |
Correct |
45 ms |
15164 KB |
Output is correct |
3 |
Partially correct |
64 ms |
19004 KB |
Output is partially correct |
4 |
Partially correct |
76 ms |
20000 KB |
Output is partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
5 ms |
9664 KB |
Output is partially correct |
2 |
Correct |
45 ms |
15164 KB |
Output is correct |
3 |
Partially correct |
64 ms |
19004 KB |
Output is partially correct |
4 |
Partially correct |
76 ms |
20000 KB |
Output is partially correct |
5 |
Partially correct |
79 ms |
22188 KB |
Output is partially correct |
6 |
Partially correct |
89 ms |
22836 KB |
Output is partially correct |
7 |
Partially correct |
92 ms |
22816 KB |
Output is partially correct |
8 |
Partially correct |
86 ms |
23272 KB |
Output is partially correct |
9 |
Partially correct |
67 ms |
18992 KB |
Output is partially correct |
10 |
Partially correct |
92 ms |
23364 KB |
Output is partially correct |
11 |
Partially correct |
88 ms |
23600 KB |
Output is partially correct |
12 |
Partially correct |
58 ms |
18736 KB |
Output is partially correct |
13 |
Partially correct |
57 ms |
18356 KB |
Output is partially correct |
14 |
Partially correct |
55 ms |
18104 KB |
Output is partially correct |
15 |
Partially correct |
52 ms |
17880 KB |
Output is partially correct |
16 |
Partially correct |
5 ms |
9940 KB |
Output is partially correct |
17 |
Partially correct |
49 ms |
17124 KB |
Output is partially correct |
18 |
Partially correct |
49 ms |
17124 KB |
Output is partially correct |
19 |
Partially correct |
52 ms |
17608 KB |
Output is partially correct |
20 |
Partially correct |
69 ms |
20256 KB |
Output is partially correct |
21 |
Partially correct |
79 ms |
22056 KB |
Output is partially correct |
22 |
Partially correct |
69 ms |
19748 KB |
Output is partially correct |