# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1032833 | parsadox2 | Mechanical Doll (IOI18_doll) | C++17 | 114 ms | 17000 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "doll.h"
using namespace std;
const int N = 2e5 + 10;
int n , m;
vector <int> C , X , Y , adj[N];
int Solve(vector <int> vec , bool flg = true)
{
if(vec.size() == 1)
return vec[0];
X.push_back(0);
Y.push_back(0);
int now = X.size();
vector <int> v[2];
/*cout << now << " solve: " << endl;
for(auto u : vec)
cout << u << " " ;
cout << endl;*/
if(flg)
{
int tmp = 1;
while(tmp < vec.size())
tmp *= 2;
vector <int> fake;
while(vec.size() + fake.size() < tmp)
fake.push_back(-now);
for(auto u : vec)
fake.push_back(u);
vec = fake;
}
if(vec[0] < 0 && vec.back() < 0)
{
X[now - 1] = vec[0];
Y[now - 1] = vec[0];
return -now;
}
for(int i = 0 ; i < vec.size() ; i++)
{
if(vec[i] < 0)
{
if(v[0].size() * 2 != vec.size())
v[0].push_back(vec[i]);
else
v[1].push_back(vec[i]);
continue;
}
if(v[0].size() > v[1].size())
v[1].push_back(vec[i]);
else
v[0].push_back(vec[i]);
}
int tmp = Solve(v[0] , 0);
X[now - 1] = tmp;
tmp = Solve(v[1] , 0);
Y[now - 1] = tmp;
return -1 * now;
}
void Build(int v)
{
if(adj[v].empty())
{
C[v] = 0;
return;
}
int tmp = Solve(adj[v]);
C[v] = tmp;
}
void create_circuit(int mm , vector <int> A)
{
n = A.size();
m = mm;
C.resize(m + 1);
adj[0].push_back(A[0]);
for(int i = 0 ; i + 1 < n ; i++)
adj[A[i]].push_back(A[i + 1]);
adj[A.back()].push_back(0);
for(int i = 0 ; i <= m ; i++)
{
Build(i);
}
/*for(int i = 0 ; i <= m ; i++)
cout << i << " -> " << C[i] << endl;
for(int i = 0 ; i < X.size() ; i++)
cout << -(i + 1) << " : " << X[i] << " " << Y[i] << endl;*/
answer(C , X , Y);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |