Submission #111449

# Submission time Handle Problem Language Result Execution time Memory
111449 2019-05-15T11:43:30 Z tjd229 Hidden Sequence (info1cup18_hidden) C++14
100 / 100
12 ms 512 KB
#include<bits/stdc++.h>
#include "grader.h"

//#include <vector>
using namespace std;
int len[200];
vector < int > findSequence (int N)
{
    vector < int > ans (N, 0);
	int L = (N >> 1) + 1;	
	int cnt[2];
	int i,j;
	if (isSubsequence({ 1 })) {
		int least = 0;
		cnt[0] = cnt[1] = 0;
		vector<int> v(L, 0),inc,dec;
		if (isSubsequence(v)) least = 1;
		int common = 1 - least;
		cnt[least] = -1;
		for (v.clear(), i = 0; isSubsequence(v); ++i) {
			v.push_back(least);
			++cnt[least];
		}
		cnt[common] = N - cnt[least];
		v.clear();
		int sum = 0; //accum least 
		for (i = 0; i < cnt[common]; ++i) {//calc len
			inc.clear();
			dec = v;
			for (j = 0; j < sum; ++j) inc.push_back(least);//[0:sum-1]=least
			for (j = i; j < cnt[common]; ++j) inc.push_back(common);
			for (dec.push_back(common),j = 0; j <1+ cnt[least] - sum; ++j) dec.push_back(least);
			for (;;++len[i]) {//j
				//inc push_front
				inc[sum + len[i]] = least;
				inc.push_back(common);
				//dec pop bk
				dec.pop_back();
				if (inc.size() <= dec.size()) {
					if (!isSubsequence(inc)) break;
				}
				else if (isSubsequence(dec)) break;				
			}
			v.push_back(common);
			sum += len[i];
		}
		/*printf("c:%d,l:%d\n",common,least);
		for (i = 0; i < cnt[common]; ++i)
			printf("l:%d\n",len[i]);
		printf("r:%d-%d=%d\n",cnt[least],sum,cnt[least]-sum);
		printf("%d,%d\n",cnt[0],cnt[1]);*/
		int ix = 0;
		for (i = 0; i < cnt[common]; ++i) {
			while (len[i]--) ans[ix++] = least;
			ans[ix++] = common;
		}
		int r = cnt[least] - sum;
		while (r--) ans[ix++] = least;
	}
    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 400 KB Output is correct: Maximum length of a query = 5
2 Correct 2 ms 256 KB Output is correct: Maximum length of a query = 6
3 Correct 2 ms 252 KB Output is correct: Maximum length of a query = 5
4 Correct 2 ms 256 KB Output is correct: Maximum length of a query = 5
5 Correct 2 ms 256 KB Output is correct: Maximum length of a query = 4
# Verdict Execution time Memory Grader output
1 Correct 6 ms 512 KB Output is correct: Maximum length of a query = 83
2 Correct 5 ms 384 KB Output is correct: Maximum length of a query = 90
3 Correct 6 ms 256 KB Output is correct: Maximum length of a query = 96
4 Correct 5 ms 256 KB Output is correct: Maximum length of a query = 77
5 Correct 7 ms 256 KB Output is correct: Maximum length of a query = 95
6 Correct 5 ms 384 KB Output is correct: Maximum length of a query = 87
7 Correct 6 ms 384 KB Output is correct: Maximum length of a query = 97
8 Correct 4 ms 412 KB Output is correct: Maximum length of a query = 83
9 Correct 4 ms 324 KB Output is correct: Maximum length of a query = 101
10 Correct 5 ms 256 KB Output is correct: Maximum length of a query = 100
11 Correct 10 ms 384 KB Output is correct: Maximum length of a query = 96
12 Correct 5 ms 256 KB Output is correct: Maximum length of a query = 100
13 Correct 12 ms 412 KB Output is correct: Maximum length of a query = 101