Submission #362010

# Submission time Handle Problem Language Result Execution time Memory
362010 2021-02-01T14:33:12 Z ogibogi2004 Hidden Sequence (info1cup18_hidden) C++14
100 / 100
8 ms 492 KB
#include<bits/stdc++.h>
#include "grader.h"

using namespace std;

vector < int > findSequence (int N)
{
    vector < int > ans;
    int cnt0,cnt1=-1,n=N,halfn=n/2+1;
    vector<int>ivan;
    for(int i=1;i<=halfn;i++)
    {
		ivan.clear();
		for(int j=0;j<i;j++)
		{
			ivan.push_back(1);
		}
		if(!isSubsequence(ivan))
		{
			cnt1=i-1;
			cnt0=n-cnt1;
			break;
		}
	}
	if(cnt1==-1)
	{
		for(int i=1;i<=halfn;i++)
		{
			ivan.clear();
			for(int j=0;j<i;j++)
			{
				ivan.push_back(0);
			}
			if(!isSubsequence(ivan))
			{
				cnt0=i-1;
				cnt1=n-cnt0;
				break;
			}
		}
	}
	while(ans.size()<n)
	{
		if(cnt0==0)
		{
			ans.push_back(1);
			cnt1--;
			continue;
		}
		if(cnt1==0)
		{
			ans.push_back(0);
			cnt0--;
			continue;
		}
		vector<int>ivan1,ivan2;
		for(int i=0;i<ans.size();i++)
		{
			if(ans[i]==0)ivan1.push_back(0);
			else ivan2.push_back(1);
		}
		ivan1.push_back(0);
		ivan2.push_back(1);
		for(int i=0;i<cnt1;i++)ivan1.push_back(1);
		for(int i=0;i<cnt0;i++)ivan2.push_back(0);
		if(ivan1.size()<ivan2.size())
		{
			if(isSubsequence(ivan1))
			{
				ans.push_back(0);
				cnt0--;
			}
			else 
			{
				ans.push_back(1);
				cnt1--;
			}
		}
		else
		{
			if(isSubsequence(ivan2))
			{
				ans.push_back(1);
				cnt1--;
			}
			else 
			{
				ans.push_back(0);
				cnt0--;
			}
		}
	}
    return ans;
}

Compilation message

hidden.cpp: In function 'std::vector<int> findSequence(int)':
hidden.cpp:42:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   42 |  while(ans.size()<n)
      |        ~~~~~~~~~~^~
hidden.cpp:57:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |   for(int i=0;i<ans.size();i++)
      |               ~^~~~~~~~~~~
hidden.cpp:44:3: warning: 'cnt0' may be used uninitialized in this function [-Wmaybe-uninitialized]
   44 |   if(cnt0==0)
      |   ^~
grader.cpp: In function 'int main()':
grader.cpp:28:26: warning: format '%d' expects argument of type 'int', but argument 3 has type 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wformat=]
   28 |     fprintf (fifo_out, "%d\n", ans.size ());
      |                         ~^     ~~~~~~~~~~~
      |                          |              |
      |                          int            std::vector<int>::size_type {aka long unsigned int}
      |                         %ld
grader.cpp:29:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for (int i=0; i<ans.size () && i < N; i++)
      |                   ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct: Maximum length of a query = 5
2 Correct 1 ms 364 KB Output is correct: Maximum length of a query = 6
3 Correct 1 ms 364 KB Output is correct: Maximum length of a query = 5
4 Correct 1 ms 364 KB Output is correct: Maximum length of a query = 5
5 Correct 1 ms 364 KB Output is correct: Maximum length of a query = 4
# Verdict Execution time Memory Grader output
1 Correct 5 ms 364 KB Output is correct: Maximum length of a query = 83
2 Correct 5 ms 364 KB Output is correct: Maximum length of a query = 90
3 Correct 6 ms 364 KB Output is correct: Maximum length of a query = 96
4 Correct 4 ms 364 KB Output is correct: Maximum length of a query = 77
5 Correct 6 ms 364 KB Output is correct: Maximum length of a query = 95
6 Correct 5 ms 492 KB Output is correct: Maximum length of a query = 87
7 Correct 7 ms 364 KB Output is correct: Maximum length of a query = 97
8 Correct 5 ms 364 KB Output is correct: Maximum length of a query = 83
9 Correct 7 ms 364 KB Output is correct: Maximum length of a query = 101
10 Correct 8 ms 364 KB Output is correct: Maximum length of a query = 100
11 Correct 6 ms 364 KB Output is correct: Maximum length of a query = 96
12 Correct 8 ms 364 KB Output is correct: Maximum length of a query = 100
13 Correct 6 ms 364 KB Output is correct: Maximum length of a query = 101