# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
139337 | wilwxk | Mechanical Doll (IOI18_doll) | C++14 | 0 ms | 0 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 "doll.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN=2e5+5;
map<int, int> mp;
int faz[MAXN*2];
vector<int> c, x, y, quero;
int n, m, cont;
void debug() {
for(auto cur : c) printf("%d ", cur); cout << endl;
for(auto cur : x) printf("%d ", cur); cout << endl;
for(auto cur : y) printf("%d ", cur); cout << endl;
}
void decompoe(int val) {
mp[1]=val;
int cur=1;
while(1) {
int qtd=mp[cur]-2;
if(qtd<=0) break;
mp[cur*2]+=qtd/2;
mp[cur]-=(qtd/2)*2;
cur*=2;
}
for(auto mit : mp) for(int i=0; i<mit.second; i++) quero.push_back(mit.first);
// for(auto cur : quero) printf("%d ", cur);
// printf("vla3\n");
}
void create_circuit(int M, std::vector<int> A) {
n=A.size(); m=M;
if(n==1) {
c.push_back(1);
c.push_back(0);
answer(c, x, y);
return 0;
}
decompoe(n);
c.push_back(1);
c.push_back(--cont);
int ult=1;
for(int i=1; i<quero.size(); i++) {
// printf("%d cuida do %d\n", cont, quero[i]);
if(quero[i]!=quero[i-1]) {
if(cont+2==0) x.push_back(1);
else x.push_back(cont+2);
y.push_back(cont-1);
}
else {
if(cont+1==0) x.push_back(1);
else x.push_back(cont+1);
y.push_back(cont-1);
}
cont--;
}
y.back()=0;
// debug();
answer(c, x, y);
}