Submission #248551

#TimeUsernameProblemLanguageResultExecution timeMemory
248551kostia244Mechanical Doll (IOI18_doll)C++17
100 / 100
256 ms11568 KiB
#include "doll.h"
#include<bits/stdc++.h>
using namespace std;
const int inf = 1<<29;
int n, m;
vector<int> x, y;
int build(vector<int> a, int S) {
	//cout << S << " " << a.size() << endl;
	if(a.empty() || a.back() == -1) return -1;
	if(S == 1) return -inf;
	x.push_back(0);
	y.push_back(0);
	int id = (int)x.size();
	int cur = 1, t = max(0, (int)a.size() - (S/2));
	vector<int> b[2];
	//for(auto i : a) cout << i << " "; cout << "\n to \n";
	while(a.size()) {
		if(b[0].size() == t && !cur) cur = 1;
		b[cur].push_back(a.back());
		a.pop_back();
		cur ^= 1;
	}
	for(int j = 0; j < 2; j++){
		reverse(b[j].begin(), b[j].end());
		//for(auto i : b[j]) cout << i << " "; cout << '\n';
	}
	int tt = build(b[0], S/2);
	x[id-1] = tt;
	tt = build(b[1], S/2);
	y[id-1] = tt;
	return -id;
}
void create_circuit(int M, vector<int> A) {
	m = M, n = A.size();
	A.push_back(0);
	int t = A.size();
	while(t&(t-1)) t++;
	build(A, t);
	//for(int i = 0; i < x.size(); i++) cout << i+1 << " " << x[i] << " " << y[i] << '\n';
	int id = 0;
	vector<int> st(x.size());
	for(int p = 0, j = 0, i = 0; j < A.size(); i++) {
		if(p < 0 && (st[-p - 1] ? y : x)[-p - 1] == -inf) {
			(st[-p - 1] ? y : x)[-p - 1] = A[j++];
		}
		if(p < 0) {
			p = -p - 1;
			int op = p;
			if(!st[p]) st[p] = 1, p = x[p];
			else st[p] = 0, p = y[p];
		} else p = -1;
	}
	//cout << '\n';
	answer(vector<int>(m+1, -1), x, y);
}

Compilation message (stderr)

doll.cpp: In function 'int build(std::vector<int>, int)':
doll.cpp:18:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   18 |   if(b[0].size() == t && !cur) cur = 1;
      |      ~~~~~~~~~~~~^~~~
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:42:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |  for(int p = 0, j = 0, i = 0; j < A.size(); i++) {
      |                               ~~^~~~~~~~~~
doll.cpp:48:8: warning: unused variable 'op' [-Wunused-variable]
   48 |    int op = p;
      |        ^~
doll.cpp:40:6: warning: unused variable 'id' [-Wunused-variable]
   40 |  int id = 0;
      |      ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...