Submission #418992

# Submission time Handle Problem Language Result Execution time Memory
418992 2021-06-06T09:50:46 Z MeGustaElArroz23 Mechanical Doll (IOI18_doll) C++14
53 / 100
165 ms 23908 KB
#include<bits/stdc++.h>
#include "doll.h"

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<vii> vvii;

#define deb(x) cerr << #x << " = " << x << ", ";
#define br cerr<<'\n';
#define debr(x) cerr << #x<<" = "<<x<<'\n';
void debv_(auto v){
  	for (int x:v) cerr << x<<", ";
 	cerr<<'\n';
}
#define debv(x) cerr<< #x<<" = ", debv_(x); 

int counter=1;
vii xy(1);
const int INF=1000000000;

int v2(int x){
	int sol=0;
	int ac=1;
	while (ac<x){
		sol++;
		ac*=2;
	}
	return sol;
}

int create_xy(vi v, int prof,int padre){
	if (prof<-10) return 0;
	//debv(v);
	// debr(prof);
	if (v.size()==1){
		if(prof==0) return v[0];
		else{
			xy.push_back(pii{padre,v[0]});
			counter++;
			return -counter+1;
		}
	}
	if (v.size()==2 and prof==1){
		xy.push_back(pii{v[0],v[1]});
		counter++;
		return -counter+1;
	}
	xy.push_back(pii{});
	int ind=counter;
	counter++;
	vi der;
	vi izq;

	int hastadonde=1;
	for (int i=0;i<prof-1;i++) hastadonde*=2;
	for (int i=0;i<v.size()-hastadonde;i++){
		if (i%2==0) izq.push_back(v[i]);
		else der.push_back(v[i]);
	}
	for (int i=v.size()-hastadonde;i<v.size();i++){
		if ((i+v.size()+hastadonde)%2==0) izq.push_back(v[i]);
		else der.push_back(v[i]);
	}

	xy[ind]=pii{create_xy(izq,prof-1,padre),create_xy(der,prof-1,padre)};
	return -ind;
}

void create_circuit(int n, vi ciclo) {
    int m=ciclo.size();
    ciclo.push_back(0);
    vvi conexiones(n+1);
    for (int i=0;i<m;i++) conexiones[ciclo[i]].push_back(ciclo[i+1]);
	for (int i=1;i<n+1;i++){
		if (conexiones[i].size()==0) conexiones[i].push_back(i);
	}
	vi salidas(n+1);
	salidas[0]=ciclo[0];
	for (int i=1;i<n+1;i++) salidas[i]=create_xy(conexiones[i],v2(conexiones[i].size()),-counter);
	vi switchX,switchY;

	for (int i=1;i<xy.size();i++){
		switchX.push_back(xy[i].first);
		switchY.push_back(xy[i].second);
	}
	//debv(salidas);
	//debv(switchX);
	//debv(switchY);
    answer(salidas, switchX, switchY);
}

Compilation message

doll.cpp:15:12: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   15 | void debv_(auto v){
      |            ^~~~
doll.cpp: In function 'int create_xy(vi, int, int)':
doll.cpp:60:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |  for (int i=0;i<v.size()-hastadonde;i++){
      |               ~^~~~~~~~~~~~~~~~~~~~
doll.cpp:64:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |  for (int i=v.size()-hastadonde;i<v.size();i++){
      |                                 ~^~~~~~~~~
doll.cpp: In function 'void create_circuit(int, vi)':
doll.cpp:86:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |  for (int i=1;i<xy.size();i++){
      |               ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 45 ms 7464 KB Output is correct
3 Correct 27 ms 5048 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 23 ms 6948 KB Output is correct
6 Correct 42 ms 7640 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 45 ms 7464 KB Output is correct
3 Correct 27 ms 5048 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 23 ms 6948 KB Output is correct
6 Correct 42 ms 7640 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 56 ms 7924 KB Output is correct
9 Correct 77 ms 9664 KB Output is correct
10 Correct 85 ms 12020 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 288 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 45 ms 7464 KB Output is correct
3 Correct 27 ms 5048 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 23 ms 6948 KB Output is correct
6 Correct 42 ms 7640 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 56 ms 7924 KB Output is correct
9 Correct 77 ms 9664 KB Output is correct
10 Correct 85 ms 12020 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 288 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 120 ms 14804 KB Output is correct
15 Correct 61 ms 7940 KB Output is correct
16 Correct 95 ms 11868 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 102 ms 13460 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 204 KB Output is partially correct
2 Correct 71 ms 7560 KB Output is correct
3 Partially correct 105 ms 13088 KB Output is partially correct
4 Partially correct 131 ms 15912 KB Output is partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 204 KB Output is partially correct
2 Correct 71 ms 7560 KB Output is correct
3 Partially correct 105 ms 13088 KB Output is partially correct
4 Partially correct 131 ms 15912 KB Output is partially correct
5 Partially correct 142 ms 19180 KB Output is partially correct
6 Partially correct 154 ms 21500 KB Output is partially correct
7 Partially correct 146 ms 20984 KB Output is partially correct
8 Partially correct 158 ms 23280 KB Output is partially correct
9 Partially correct 108 ms 15276 KB Output is partially correct
10 Partially correct 165 ms 23908 KB Output is partially correct
11 Partially correct 161 ms 23280 KB Output is partially correct
12 Partially correct 103 ms 15256 KB Output is partially correct
13 Partially correct 96 ms 13900 KB Output is partially correct
14 Partially correct 112 ms 13496 KB Output is partially correct
15 Partially correct 91 ms 12320 KB Output is partially correct
16 Partially correct 3 ms 588 KB Output is partially correct
17 Partially correct 92 ms 11972 KB Output is partially correct
18 Partially correct 92 ms 12052 KB Output is partially correct
19 Partially correct 94 ms 12724 KB Output is partially correct
20 Partially correct 128 ms 17220 KB Output is partially correct
21 Partially correct 149 ms 19960 KB Output is partially correct
22 Partially correct 127 ms 15164 KB Output is partially correct