#include "doll.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=(a);i<(b);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define F first
#define S second
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void amin(ll &a, ll b){ a=min(a,b); }
void amax(ll &a, ll b){ a=max(a,b); }
void YES(){cout<<"YES\n";} void NO(){cout<<"NO\n";}
void SD(int t=0){ cout<<"PASSED "<<t<<endl; }
const ll INF = ll(1e18);
const int MOD = 998244353;
const bool DEBUG = 0;
const int MAXN = 200005;
vector<int> c,x,y;
int dfs(int prt, vector<int> nxt)
{
if(nxt.size()==1)
{
if(prt<0) x.pb(prt);
else x.pb(-(int)x.size()-1);
y.pb(nxt[0]);
if(DEBUG) cout<<"Base 1: "<<-(int)x.size()<<" -> "<<x.back()<<", "<<y.back()<<'\n';
return -(int)x.size();
}
if(nxt.size()==2)
{
x.pb(nxt[0]);
y.pb(nxt[1]);
if(DEBUG) cout<<"Base 2: "<<-(int)x.size()<<" -> "<<x.back()<<", "<<y.back()<<'\n';
return -(int)x.size();
}
int mid=1;
while(mid<<1 < nxt.size()) mid<<=1;
vector<int> tmp[2];
for(int i=0;i<nxt.size();i++) tmp[i%2].pb(nxt[i]);
int z = nxt.size()%2;
nxt.clear();
x.emplace_back();
y.emplace_back();
int self = x.size();
int nxtx = dfs(-self, tmp[z]);
int nxty = dfs(-self, tmp[z^1]);
x[self-1]=nxtx;
y[self-1]=nxty;
if(DEBUG) cout<<"Normal: "<<-self<<" -> "<<nxtx<<", "<<nxty<<'\n';
return -self;
}
void create_circuit(int m, vector<int> a)
{
int n = a.size();
c.resize(m+1);
vector<int> nxt[m+1];
forn(i,0,n-1){
nxt[a[i]].pb(a[i+1]);
}
nxt[a[n-1]].pb(0);
if(DEBUG){
fore(i,1,m){
cout<<"nxt["<<i<<"]=";
for(int x: nxt[i]) cout<<x<<" ";
cout<<'\n';
}
}
c[0]=a[0];
if(DEBUG) cout<<"c["<<0<<"] -> "<<c[0]<<'\n';
fore(i,1,m){
if(nxt[i].empty()){
c[i]=i;
if(DEBUG) cout<<"c["<<i<<"] -> "<<c[i]<<" (to self)\n";
continue;
}
c[i]=dfs(i, nxt[i]);
if(DEBUG) cout<<"c["<<i<<"] -> "<<c[i]<<'\n';
}
answer(c,x,y);
}
Compilation message
doll.cpp: In function 'int dfs(int, std::vector<int>)':
doll.cpp:56:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | while(mid<<1 < nxt.size()) mid<<=1;
| ~~~~~~~^~~~~~~~~~~~
doll.cpp:59:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for(int i=0;i<nxt.size();i++) tmp[i%2].pb(nxt[i]);
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
57 ms |
8444 KB |
Output is correct |
3 |
Correct |
47 ms |
7616 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
17 ms |
3908 KB |
Output is correct |
6 |
Correct |
84 ms |
10640 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
57 ms |
8444 KB |
Output is correct |
3 |
Correct |
47 ms |
7616 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
17 ms |
3908 KB |
Output is correct |
6 |
Correct |
84 ms |
10640 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
61 ms |
7796 KB |
Output is correct |
9 |
Correct |
78 ms |
10072 KB |
Output is correct |
10 |
Correct |
117 ms |
11064 KB |
Output is correct |
11 |
Correct |
2 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
57 ms |
8444 KB |
Output is correct |
3 |
Correct |
47 ms |
7616 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
17 ms |
3908 KB |
Output is correct |
6 |
Correct |
84 ms |
10640 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
61 ms |
7796 KB |
Output is correct |
9 |
Correct |
78 ms |
10072 KB |
Output is correct |
10 |
Correct |
117 ms |
11064 KB |
Output is correct |
11 |
Correct |
2 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
144 ms |
11740 KB |
Output is correct |
15 |
Correct |
69 ms |
5888 KB |
Output is correct |
16 |
Correct |
92 ms |
8952 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
2 ms |
240 KB |
Output is correct |
20 |
Correct |
125 ms |
11504 KB |
Output is correct |
21 |
Correct |
3 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
wrong motion |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
wrong motion |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
wrong motion |
2 |
Halted |
0 ms |
0 KB |
- |