Submission #120208

# Submission time Handle Problem Language Result Execution time Memory
120208 2019-06-23T23:02:27 Z dsjong Mechanical Doll (IOI18_doll) C++14
18 / 100
110 ms 7488 KB
//SUBTASK 5
#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
bool val[1000005];
int simulate(int N,vector<int>&X,vector<int>&Y){
	memset(val,0,sizeof val);
	int ans;
	for(int i=1;i<=N;i++){
		int j=1;
		while(j!=0){
			ans=j;
			val[j]^=1;
			if(val[j]) j=X[j-1];
			else j=Y[j-1];
		}
	}
	return ans-1;
}
void create_circuit(int M, vector<int> A){
	int N=A.size();
	vector<int>levels;
	vector<int>C;
	C.push_back(1);
	C.push_back(-1);
	int x=N,S=0;
	while(x>1){
		x=(x+1)/2;
		S+=x;
		levels.push_back(x);
	}
	reverse(levels.begin(),levels.end());
	vector<int>X(S),Y(S);
	for(int i=0;i<S;i++){
		X[i]=0;
		Y[i]=0;
	}
	int cur=0,sum=1;
	for(int i=0;i<levels.size()-1;i++){
		if(levels[i+1]==2*levels[i]){
			X[cur]=++sum;
			Y[cur]=++sum;
			cur++;
		}
		else{
			X[cur]=++sum;
			Y[cur]=1;
			cur++;
		}
		for(int j=1;j<=levels[i]-1;j++){
			X[cur]=++sum;
			Y[cur]=++sum;
			cur++;
		}
	}
	int curry=simulate(2*levels.back(),X,Y);
	for(int i=1;i<=levels.back();i++){
		X[cur]=Y[cur]=-1;
		cur++;
	}
	if(N%2==0) X[curry]=-1;
	else X[curry]=1;
	Y[curry]=0;
	for(int i=0;i<S;i++){
		X[i]*=-1;
		Y[i]*=-1;
	}
	answer(C,X,Y);
}

Compilation message

doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:39:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |  for(int i=0;i<levels.size()-1;i++){
      |              ~^~~~~~~~~~~~~~~~
doll.cpp: In function 'int simulate(int, std::vector<int>&, std::vector<int>&)':
doll.cpp:18:13: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   18 |  return ans-1;
      |             ^
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 1228 KB Wrong Answer: wrong array length
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 1228 KB Wrong Answer: wrong array length
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 1228 KB Wrong Answer: wrong array length
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 1228 KB Wrong Answer: wrong array length
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1228 KB Output is correct
2 Correct 68 ms 5376 KB Output is correct
3 Correct 70 ms 5388 KB Output is correct
4 Correct 110 ms 7488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1228 KB Output is correct
2 Correct 68 ms 5376 KB Output is correct
3 Correct 70 ms 5388 KB Output is correct
4 Correct 110 ms 7488 KB Output is correct
5 Incorrect 70 ms 5948 KB Wrong Answer: wrong array length
6 Halted 0 ms 0 KB -