#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<n;++i)
#define ll long long
#define pb push_back
#define all(x) x.begin(), x.end()
const ll inf = 1e18;
#define pi pair<int,int>
#define f first
#define s second
void mysim(vector<int> c, vector<int> x, vector<int> y) {
int p=0;
int z=1;
int k=x.size();
vector<int> s(k,0);
while (z||p) {
if (!p) {
z=0; p=c[p];
} else if (p>0) {
cout<<p<<"->\n";
p=c[p];
} else {
cout<<"? "<<p<<'\n';
int i=-p-1;
if (s[i]==0) p=x[i];
else p=y[i];
s[i]^=1;
}
}
}
void create_circuit(int m, vector<int>a) {
int n=a.size();
map<int,int> cnt;
int mx=0;
for(auto&x:a) {
cnt[x]++;
mx=max(mx,cnt[x]);
}
if (mx<=4) {
vector<int> c(m+1,0);
c[0]=a[0];
vector<int> x,y;
int nxt=0;
for(auto&it:cnt) {
int v=it.f, k=it.s;
if (k==1) continue;
if (k==2) {
x.pb(0), y.pb(0);
c[v]=-1-nxt++;
} else {
x.pb(-1-(nxt+1)), y.pb(-1-(nxt+2));
forn(i,2) x.pb(0), y.pb(0);
if (k==3) y[nxt+1]=-1-(nxt);
c[v]=-nxt-1;
nxt+=3;
}
}
map<int,int> ok;
a.pb(0);
for(int i=0;i<n;++i) {
int k=cnt[a[i]];
if (k==1) {
c[a[i]]=a[i+1];
} else if (k==2) {
if (ok[a[i]]) {
y[-c[a[i]]-1]=a[i+1];
} else {
++ok[a[i]];
x[-c[a[i]]-1]=a[i+1];
}
} else if (k==3) {
if (ok[a[i]]==0) {
x[-1-x[-c[a[i]]-1]]=a[i+1];
} else if (ok[a[i]]==1) {
x[-1-y[-c[a[i]]-1]]=a[i+1];
} else {
y[-1-y[-c[a[i]]-1]]=a[i+1];
}
++ok[a[i]];
} else {
if (ok[a[i]]==0) {
x[-1-x[-c[a[i]]-1]]=a[i+1];
} else if (ok[a[i]]==1) {
x[-1-y[-c[a[i]]-1]]=a[i+1];
} else if (ok[a[i]]==2) {
y[-1-x[-c[a[i]]-1]]=a[i+1];
} else {
y[-1-y[-c[a[i]]-1]]=a[i+1];
}
++ok[a[i]];
}
}
//forn(i,m+1) cout<<c[i]<<' '; cout<<'\n';
//forn(i,x.size()) cout<<x[i]<<' '<<y[i]<<'\n';
//mysim(c,x,y);
answer(c,x,y);
return;
}
vector<int> c(m+1,-1); c[0]=a[0];
int sz=1; while (2*sz<n) sz<<=1;
vector<int> x(2*sz-1,-1), y(2*sz-1,-1);
forn(i,sz-1) x[i]=2*i+1, y[i]=2*i+2;
forn(i,sz-1) x[i]=-1-x[i], y[i]=-1-y[i];
vector<int> s(2*sz-1,1);
vector<pi> z;
forn(it,2*sz) {
int p=0;
while (p<sz-1) {
s[p]^=1;
p=2*p+1+s[p];
}
s[p]^=1;
z.pb({p,s[p]});
}
forn(i,n-1) {
if (z[i].s) y[z[i].f]=a[i+1];
else x[z[i].f]=a[i+1];
}
y[z.back().f]=0;
answer(c,x,y);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
300 KB |
Output is correct |
2 |
Correct |
45 ms |
5420 KB |
Output is correct |
3 |
Correct |
42 ms |
5104 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
8 ms |
1364 KB |
Output is correct |
6 |
Correct |
69 ms |
7588 KB |
Output is correct |
7 |
Correct |
0 ms |
304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
300 KB |
Output is correct |
2 |
Correct |
45 ms |
5420 KB |
Output is correct |
3 |
Correct |
42 ms |
5104 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
8 ms |
1364 KB |
Output is correct |
6 |
Correct |
69 ms |
7588 KB |
Output is correct |
7 |
Correct |
0 ms |
304 KB |
Output is correct |
8 |
Correct |
126 ms |
10340 KB |
Output is correct |
9 |
Correct |
115 ms |
10168 KB |
Output is correct |
10 |
Correct |
226 ms |
15456 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
300 KB |
Output is correct |
2 |
Correct |
45 ms |
5420 KB |
Output is correct |
3 |
Correct |
42 ms |
5104 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
8 ms |
1364 KB |
Output is correct |
6 |
Correct |
69 ms |
7588 KB |
Output is correct |
7 |
Correct |
0 ms |
304 KB |
Output is correct |
8 |
Correct |
126 ms |
10340 KB |
Output is correct |
9 |
Correct |
115 ms |
10168 KB |
Output is correct |
10 |
Correct |
226 ms |
15456 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
221 ms |
14696 KB |
Output is correct |
15 |
Correct |
137 ms |
7672 KB |
Output is correct |
16 |
Correct |
207 ms |
11280 KB |
Output is correct |
17 |
Correct |
1 ms |
300 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
209 ms |
13956 KB |
Output is correct |
21 |
Correct |
1 ms |
300 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
300 KB |
Output is partially correct |
2 |
Correct |
36 ms |
6548 KB |
Output is correct |
3 |
Partially correct |
78 ms |
11232 KB |
Output is partially correct |
4 |
Partially correct |
73 ms |
11748 KB |
Output is partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
300 KB |
Output is partially correct |
2 |
Correct |
36 ms |
6548 KB |
Output is correct |
3 |
Partially correct |
78 ms |
11232 KB |
Output is partially correct |
4 |
Partially correct |
73 ms |
11748 KB |
Output is partially correct |
5 |
Partially correct |
142 ms |
13988 KB |
Output is partially correct |
6 |
Partially correct |
121 ms |
12980 KB |
Output is partially correct |
7 |
Partially correct |
118 ms |
13372 KB |
Output is partially correct |
8 |
Partially correct |
105 ms |
12320 KB |
Output is partially correct |
9 |
Partially correct |
64 ms |
11196 KB |
Output is partially correct |
10 |
Partially correct |
86 ms |
12100 KB |
Output is partially correct |
11 |
Partially correct |
87 ms |
11720 KB |
Output is partially correct |
12 |
Partially correct |
75 ms |
11188 KB |
Output is partially correct |
13 |
Correct |
63 ms |
7356 KB |
Output is correct |
14 |
Partially correct |
92 ms |
12300 KB |
Output is partially correct |
15 |
Partially correct |
96 ms |
12636 KB |
Output is partially correct |
16 |
Partially correct |
3 ms |
724 KB |
Output is partially correct |
17 |
Correct |
48 ms |
6536 KB |
Output is correct |
18 |
Correct |
44 ms |
6552 KB |
Output is correct |
19 |
Partially correct |
74 ms |
11164 KB |
Output is partially correct |
20 |
Partially correct |
102 ms |
11896 KB |
Output is partially correct |
21 |
Partially correct |
84 ms |
11652 KB |
Output is partially correct |
22 |
Partially correct |
93 ms |
11768 KB |
Output is partially correct |