Submission #96492

# Submission time Handle Problem Language Result Execution time Memory
96492 2019-02-09T17:55:16 Z dnass Hidden Sequence (info1cup18_hidden) C++14
59 / 100
9 ms 400 KB
#include <cstdio>
#include <vector>
#include <ctime>
#include <cstdlib>
#include "grader.h"
using namespace std;

int n;
int halfp;
int ones = -1, zeros = -1;
int onesones, zeroszeros;

vector<int> findSequence (int N){
	n = N;
	halfp = (n/2)+1;
	vector<int> half_ones;
	for(int i=1;i<=halfp;i++){
		half_ones.push_back(1);
		if(!isSubsequence(half_ones)){
			ones = i-1;
			break;
		}
	}
	if(ones!=-1){
		zeros = n-ones;
	}else{
		vector<int> half_zeros;
		for(int i=1;i<=halfp;i++){
			half_zeros.push_back(0);
			if(!isSubsequence(half_zeros)){
				zeros = i-1;
				break;
			}
		}
		ones = n-zeros;
	}
	onesones = ones;
	zeroszeros = zeros;
	vector<int> ans;
	if(ones==n){
		for(int i=0;i<n;i++) ans.push_back(1);
	}else if(zeros==n){
		for(int i=0;i<n;i++) ans.push_back(0);
	}else if(zeros>=ones){
		vector<int> subs;
		subs.push_back(0);
		for(int i=0;i<ones;i++) subs.push_back(1);
		while((int)subs.size()<=halfp&&(onesones+zeroszeros)>1){
			if(isSubsequence(subs)){
				ans.push_back(0);
				subs.insert(subs.begin(), 0);
				zeroszeros--;
			}else{
				ans.push_back(1);
				subs.erase(subs.end()-1);
				onesones--;
			}
		}
		if(onesones+zeroszeros>1){
			subs.clear();
			for(int i=0;i<ones-onesones+1;i++) subs.push_back(1);
			for(int i=0;i<zeroszeros;i++) subs.push_back(0);
			while(onesones+zeroszeros>1){
				if(isSubsequence(subs)){
					ans.push_back(1);
					subs.insert(subs.begin(), 1);
					onesones--;
				}else{
					ans.push_back(0);
					subs.erase(subs.end()-1);
					zeroszeros--;
				}
			}
		}
		if(onesones==1) ans.push_back(1);
		else ans.push_back(0);
	}else{
		vector<int> subs;
		subs.push_back(1);
		for(int i=0;i<zeros;i++) subs.push_back(0);
		while((int)subs.size()<=halfp&&(onesones+zeroszeros)>1){
			if(isSubsequence(subs)){
				ans.push_back(1);
				subs.insert(subs.begin(), 1);
				onesones--;
			}else{
				ans.push_back(0);
				subs.erase(subs.end()-1);
				zeroszeros--;
			}
		}
		if(onesones+zeroszeros>1){
			subs.clear();
			for(int i=0;i<zeros-zeroszeros+1;i++) subs.push_back(0);
			for(int i=0;i<onesones;i++) subs.push_back(1);
			while(onesones+zeroszeros>1){
				if(isSubsequence(subs)){
					ans.push_back(0);
					subs.insert(subs.begin(), 0);
					zeroszeros--;
				}else{
					ans.push_back(1);
					subs.erase(subs.end()-1);
					onesones--;
				}
			}
		}
		if(onesones==1) ans.push_back(1);
		else ans.push_back(0);
	}
    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 Partially correct 2 ms 248 KB Output is partially correct: Maximum length of a query = 6
2 Partially correct 2 ms 248 KB Output is partially correct: Maximum length of a query = 8
3 Partially correct 2 ms 376 KB Output is partially correct: Maximum length of a query = 6
4 Correct 2 ms 376 KB Output is correct: Maximum length of a query = 5
5 Partially correct 2 ms 248 KB Output is partially correct: Maximum length of a query = 5
# Verdict Execution time Memory Grader output
1 Partially correct 4 ms 312 KB Output is partially correct: Maximum length of a query = 86
2 Partially correct 4 ms 312 KB Output is partially correct: Maximum length of a query = 95
3 Partially correct 4 ms 312 KB Output is partially correct: Maximum length of a query = 99
4 Correct 3 ms 316 KB Output is correct: Maximum length of a query = 77
5 Partially correct 5 ms 316 KB Output is partially correct: Maximum length of a query = 102
6 Partially correct 6 ms 396 KB Output is partially correct: Maximum length of a query = 100
7 Partially correct 7 ms 248 KB Output is partially correct: Maximum length of a query = 135
8 Partially correct 6 ms 248 KB Output is partially correct: Maximum length of a query = 111
9 Partially correct 8 ms 376 KB Output is partially correct: Maximum length of a query = 106
10 Partially correct 9 ms 400 KB Output is partially correct: Maximum length of a query = 105
11 Correct 7 ms 376 KB Output is correct: Maximum length of a query = 96
12 Partially correct 8 ms 376 KB Output is partially correct: Maximum length of a query = 101
13 Partially correct 8 ms 400 KB Output is partially correct: Maximum length of a query = 106