Submission #96489

# Submission time Handle Problem Language Result Execution time Memory
96489 2019-02-09T17:14:32 Z KLPP Hidden Sequence (info1cup18_hidden) C++14
0 / 100
380 ms 580 KB
#include<bits/stdc++.h>
#include "grader.h"

using namespace std;

vector < int > findSequence (int N)
{
	int zeros,ones;
	zeros=-1;
	ones=-1;
	for(int i=1;i<=N/2+1;i++){
		vector<int> query(i);
		for(int j=0;j<i;j++)query[j]=0;
		if(!isSubsequence(query)){
			zeros=i-1;
			i=N/2+1;
		}
	}
	if(zeros!=-1)ones=N-zeros;
	for(int i=1;i<=N/2+1;i++){
		vector<int> query(i);
		for(int j=0;j<i;j++)query[j]=1;
		if(!isSubsequence(query)){
			ones=i-1;
			i=N/2+1;
		}
	}
	if(ones!=-1)zeros=N-ones;
	vector<int> ans;
	if(zeros==0){
		for(int i=0;i<N;i++)ans.push_back(1);
		return ans;
	}
	if(ones==0){
		for(int i=0;i<N;i++)ans.push_back(0);
		return ans;
	}
	vector<int> query;
	int obj=0;
	if(zeros>=ones){
		obj=1;
		swap(ones,zeros);
	}
	int maxLength=N/2;
	maxLength++;
	//cout<<obj<<" "<<zeros<<" "<<ones<<" "<<maxLength<<endl;
	int answer[zeros+1][zeros+1];
	for(int a=0;a<=zeros;a++){
		for(int b=0;a+b<=zeros;b++){
			int lo,hi;
			lo=0;
			hi=maxLength-a-b+1;
			//cout<<hi<<endl;
			while(hi-lo>1){//cout<<hi<<" "<<lo<<endl;
				int mid=(lo+hi)/2;
				//cout<<"M"<<mid<<endl;
				for(int i=0;i<a;i++)query.push_back(obj);
				for(int i=0;i<mid;i++)query.push_back(1-obj);
				for(int i=0;i<b;i++)query.push_back(obj);
				//cout<<"Sz"<<query.size()<<endl;
				/*for(int i=0;i<query.size();i++)cout<<query[i]<<" ";
				cout<<endl;*/
				if(!isSubsequence(query)){
					hi=mid;
				}else lo=mid;
				query.clear();
			}//cout<<hi<<" "<<lo<<endl;
			answer[a][b]=lo;
			//cout<<lo<<" ";
		}//cout<<endl;
	}
	int S[zeros+1];
	for(int i=0;i<=zeros;i++){
		S[i]=answer[0][zeros-i];
		for(int j=0;j<i;j++)S[i]=max(S[i],S[j]+answer[j+1][zeros-i]);	
	}
	int D[zeros+1];
	D[0]=S[0];
	for(int i=0;i<zeros;i++)D[i+1]=S[i+1]-S[i];
	for(int i=0;i<=zeros;i++){
		for(int j=0;j<D[i];j++)ans.push_back(1-obj);
		if(i!=zeros)ans.push_back(obj);
	}
	return ans;
}

Compilation message

grader.cpp: In function 'int main()':
grader.cpp:28:43: warning: format '%d' expects argument of type 'int', but argument 3 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
     fprintf (fifo_out, "%d\n", ans.size ());
                                ~~~~~~~~~~~^
grader.cpp:29:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0; i<ans.size () && i < N; i++)
                   ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 248 KB Output is correct: Maximum length of a query = 5
2 Correct 2 ms 248 KB Output is correct: Maximum length of a query = 6
3 Correct 2 ms 248 KB Output is correct: Maximum length of a query = 5
4 Correct 2 ms 376 KB Output is correct: Maximum length of a query = 5
5 Incorrect 2 ms 376 KB Output is not correct: The returned sequence does not match the hidden one
# Verdict Execution time Memory Grader output
1 Correct 277 ms 456 KB Output is correct: Maximum length of a query = 83
2 Correct 282 ms 580 KB Output is correct: Maximum length of a query = 90
3 Incorrect 380 ms 440 KB Output is not correct: The returned sequence does not match the hidden one
4 Halted 0 ms 0 KB -