답안 #96498

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
96498 2019-02-09T18:38:02 Z dnass Hidden Sequence (info1cup18_hidden) C++14
100 / 100
9 ms 404 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{
		while(onesones>0&&zeroszeros>0){
			//printf("o:%d z:%d\n", onesones, zeroszeros);
			vector<int> subs0;
			for(int i=0;i<zeros-zeroszeros+1;i++) subs0.push_back(0);
			for(int i=0;i<onesones;i++) subs0.push_back(1);
			vector<int> subs1;
			for(int i=0;i<ones-onesones+1;i++) subs1.push_back(1);
			for(int i=0;i<zeroszeros;i++) subs1.push_back(0);
			if((int)subs0.size()<=halfp){
				if(isSubsequence(subs0)){
					ans.push_back(0);
					zeroszeros--;
				}else{
					ans.push_back(1);
					onesones--;
				}
			}else{
				if(isSubsequence(subs1)){
					ans.push_back(1);
					onesones--;
				}else{
					ans.push_back(0);
					zeroszeros--;
				}
			}
		}
		if(onesones==0){
			for(int i=0;i<zeroszeros;i++) ans.push_back(0);
		}else if(zeroszeros==0){
			for(int i=0;i<onesones;i++) ans.push_back(1);
		}
	}
    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++)
                   ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 248 KB Output is correct: Maximum length of a query = 5
5 Correct 2 ms 376 KB Output is correct: Maximum length of a query = 4
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 316 KB Output is correct: Maximum length of a query = 83
2 Correct 9 ms 376 KB Output is correct: Maximum length of a query = 90
3 Correct 8 ms 248 KB Output is correct: Maximum length of a query = 96
4 Correct 6 ms 252 KB Output is correct: Maximum length of a query = 77
5 Correct 4 ms 312 KB Output is correct: Maximum length of a query = 95
6 Correct 7 ms 248 KB Output is correct: Maximum length of a query = 87
7 Correct 7 ms 376 KB Output is correct: Maximum length of a query = 97
8 Correct 4 ms 404 KB Output is correct: Maximum length of a query = 83
9 Correct 7 ms 248 KB Output is correct: Maximum length of a query = 101
10 Correct 9 ms 248 KB Output is correct: Maximum length of a query = 100
11 Correct 8 ms 248 KB Output is correct: Maximum length of a query = 96
12 Correct 5 ms 312 KB Output is correct: Maximum length of a query = 100
13 Correct 4 ms 320 KB Output is correct: Maximum length of a query = 101