#include "doll.h"
#include <bits/stdc++.h>
#define MAX 1000000000
using namespace std;
typedef vector<int> vi;
int vis[400010],G[400010];
vi X,Y,C;
int sw=0;
map<int,int> m;
void create_switch(int x){
int ns=2;
queue<int> q;
sw--;
int insw=sw;
q.push(sw);
C[x]=insw;
int aux=m[x];
while(ns<aux){
// cout<<ns<<endl;
int t=q.size();
for(int i=0;i<t;i++){
ns-=2;
int y=q.front();
q.pop();
X.push_back(sw-1);
Y.push_back(sw-2);
q.push(sw-1);
q.push(sw-2);
ns+=4;
sw-=2;
}
}
while(!q.empty()){
int y=q.front();
q.pop();
if(ns>aux){
X.push_back(insw); ns--;
Y.push_back(-MAX);
G[abs(y)]=-1;
}
else{
X.push_back(-MAX);
Y.push_back(-MAX);
}
}
}
bool sa=0;
int dfs(int u){
u=abs(u);
/*if(sw==-6)
cout<<u<<" "<<X[abs(u)-1]<<" "<<Y[abs(u)-1]<<" "<<G[u]<<" "<<X.size()<<endl;*/
if(G[u]==-1){
G[u]=1;
return dfs(abs(X[abs(u)-1]));
}
if(G[u]==1){
G[u]=0;
if(Y[abs(u)-1]==-MAX){
sa=1; return abs(u)-1;
}
return dfs(Y[abs(u)-1]);
}
else{
G[u]=1;
if(X[abs(u)-1]==-MAX){sa=0; return abs(u)-1;}
return dfs(X[abs(u)-1]);
}
}
void create_circuit(int M, std::vector<int> A) {
for(int i=0;i<A.size();i++){
m[A[i]]++;
}
A.push_back(0);
memset(vis,0,sizeof vis);
memset(G,0,sizeof G);
C.resize(M+1);
C[0]=A[0];
for(int i=0;i<A.size()-1;i++){
if(m[A[i]]!=1){
if(!vis[A[i]]){
//cout<<A[i]<<endl;
create_switch(A[i]);
int ids=dfs(abs(C[A[i]]));
if(sa==0) X[ids]=A[i+1];
else Y[ids]=A[i+1];
vis[A[i]]=1;
//cout<<ids<<endl;
}
else{
sa=0;
int ids=dfs(abs(C[A[i]]));
if(sa==0) X[ids]=A[i+1];
else Y[ids]=A[i+1];
//cout<<ids<<endl;
}
/*for(int i=0;i<=abs(sw);i++){
cout<<G[i]<<" ";
}
cout<<endl;*/
/* cout<<X.size()<<endl;*/
}
else{
C[A[i]]=A[i+1];
}
}
/* for(int i=0;i<C.size();i++){
cout<<C[i]<<" ";
}
cout<<endl;
cout<<X.size()<<" "<<Y.size()<<endl;*/
/*for(int i=0;i<X.size();i++) cout<<X[i]<<" ";
cout<<endl;
for(int j=0;j<Y.size();j++) cout<<Y[j]<<" ";
cout<<endl;*/
answer(C, X, Y);
}
Compilation message
doll.cpp: In function 'void create_switch(int)':
doll.cpp:23:11: warning: unused variable 'y' [-Wunused-variable]
23 | int y=q.front();
| ^
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:71:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | for(int i=0;i<A.size();i++){
| ~^~~~~~~~~
doll.cpp:79:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
79 | for(int i=0;i<A.size()-1;i++){
| ~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3404 KB |
Output is correct |
2 |
Correct |
70 ms |
8172 KB |
Output is correct |
3 |
Correct |
75 ms |
7836 KB |
Output is correct |
4 |
Correct |
3 ms |
3404 KB |
Output is correct |
5 |
Correct |
18 ms |
4556 KB |
Output is correct |
6 |
Correct |
142 ms |
10152 KB |
Output is correct |
7 |
Correct |
3 ms |
3404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3404 KB |
Output is correct |
2 |
Correct |
70 ms |
8172 KB |
Output is correct |
3 |
Correct |
75 ms |
7836 KB |
Output is correct |
4 |
Correct |
3 ms |
3404 KB |
Output is correct |
5 |
Correct |
18 ms |
4556 KB |
Output is correct |
6 |
Correct |
142 ms |
10152 KB |
Output is correct |
7 |
Correct |
3 ms |
3404 KB |
Output is correct |
8 |
Correct |
137 ms |
10560 KB |
Output is correct |
9 |
Correct |
189 ms |
11268 KB |
Output is correct |
10 |
Correct |
286 ms |
14824 KB |
Output is correct |
11 |
Correct |
3 ms |
3404 KB |
Output is correct |
12 |
Correct |
3 ms |
3404 KB |
Output is correct |
13 |
Correct |
2 ms |
3404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3404 KB |
Output is correct |
2 |
Correct |
70 ms |
8172 KB |
Output is correct |
3 |
Correct |
75 ms |
7836 KB |
Output is correct |
4 |
Correct |
3 ms |
3404 KB |
Output is correct |
5 |
Correct |
18 ms |
4556 KB |
Output is correct |
6 |
Correct |
142 ms |
10152 KB |
Output is correct |
7 |
Correct |
3 ms |
3404 KB |
Output is correct |
8 |
Correct |
137 ms |
10560 KB |
Output is correct |
9 |
Correct |
189 ms |
11268 KB |
Output is correct |
10 |
Correct |
286 ms |
14824 KB |
Output is correct |
11 |
Correct |
3 ms |
3404 KB |
Output is correct |
12 |
Correct |
3 ms |
3404 KB |
Output is correct |
13 |
Correct |
2 ms |
3404 KB |
Output is correct |
14 |
Correct |
226 ms |
15936 KB |
Output is correct |
15 |
Correct |
135 ms |
9788 KB |
Output is correct |
16 |
Correct |
218 ms |
12876 KB |
Output is correct |
17 |
Correct |
3 ms |
3404 KB |
Output is correct |
18 |
Correct |
3 ms |
3404 KB |
Output is correct |
19 |
Correct |
2 ms |
3404 KB |
Output is correct |
20 |
Correct |
246 ms |
14768 KB |
Output is correct |
21 |
Correct |
3 ms |
3404 KB |
Output is correct |
22 |
Correct |
3 ms |
3404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
3368 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
3 ms |
3404 KB |
Output is partially correct |
2 |
Correct |
75 ms |
8704 KB |
Output is correct |
3 |
Partially correct |
166 ms |
11292 KB |
Output is partially correct |
4 |
Partially correct |
143 ms |
11740 KB |
Output is partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
3 ms |
3404 KB |
Output is partially correct |
2 |
Correct |
75 ms |
8704 KB |
Output is correct |
3 |
Partially correct |
166 ms |
11292 KB |
Output is partially correct |
4 |
Partially correct |
143 ms |
11740 KB |
Output is partially correct |
5 |
Partially correct |
277 ms |
16144 KB |
Output is partially correct |
6 |
Partially correct |
239 ms |
17048 KB |
Output is partially correct |
7 |
Partially correct |
209 ms |
16584 KB |
Output is partially correct |
8 |
Partially correct |
235 ms |
17248 KB |
Output is partially correct |
9 |
Partially correct |
165 ms |
12008 KB |
Output is partially correct |
10 |
Partially correct |
260 ms |
17564 KB |
Output is partially correct |
11 |
Partially correct |
205 ms |
17540 KB |
Output is partially correct |
12 |
Partially correct |
127 ms |
12128 KB |
Output is partially correct |
13 |
Partially correct |
128 ms |
11324 KB |
Output is partially correct |
14 |
Partially correct |
195 ms |
11192 KB |
Output is partially correct |
15 |
Partially correct |
134 ms |
11016 KB |
Output is partially correct |
16 |
Partially correct |
6 ms |
3660 KB |
Output is partially correct |
17 |
Partially correct |
112 ms |
9788 KB |
Output is partially correct |
18 |
Partially correct |
120 ms |
10532 KB |
Output is partially correct |
19 |
Partially correct |
107 ms |
10216 KB |
Output is partially correct |
20 |
Partially correct |
157 ms |
13432 KB |
Output is partially correct |
21 |
Partially correct |
172 ms |
15700 KB |
Output is partially correct |
22 |
Partially correct |
145 ms |
12740 KB |
Output is partially correct |