Submission #1320737

#TimeUsernameProblemLanguageResultExecution timeMemory
1320737c4lHidden Sequence (info1cup18_hidden)C++20
10 / 100
5 ms424 KiB
#include <bits/stdc++.h>
using namespace std;
//#define ngu
#define check isSubsequence
#ifndef ngu
#include "grader.h"
#endif

#ifdef ngu
static int maxQ = 0;
static vector < int > theRealAnswer;

bool isSubsequence (vector < int > v)
{
    if (v.size () > maxQ)
        maxQ = v.size ();
    int i = 0;
    for (auto it : v)
    {
        while (i < theRealAnswer.size () && it != theRealAnswer[i]) i ++;
        if (i == theRealAnswer.size ()) return 0;
        i ++;
    }
    return 1;
}
#endif

vector<int> findSequence(int n)
{
	if(n<=10){
		int maxn = (1<<n);
		for (int i = 0;i<maxn;++i){
			vector<int> luu;
			for (int j = 0;j<n;++j){
				if(i & (1<<j))luu.push_back(1);
				else luu.push_back(0);
			}
			if(isSubsequence(luu)){
				return luu;
			}
		}
	}else{
		vector<int> luu;
		bool c = false;
		while(!c){
			luu.push_back(0);
			if(!check(luu)){
				luu.pop_back();
				luu.push_back(1);
				if(!check(luu)){
					luu.pop_back();
					c = true;
				}
			}
		}
		for (int i = 0;i<n;++i){
			bool c = false;
			while(!c){
				luu.insert(luu.begin()+i, 0);
				if(!check(luu)){
					luu.erase(luu.begin()+i);
					luu.insert(luu.begin()+i, 1);
					if(!check(luu)){
						luu.erase(luu.begin()+i);
						c = true;
					}
				}
			}
		}
		return luu;
	}
}

#ifdef ngu
int main ()
{
int n, x;
scanf ("%d", &n), maxQ = 0;
for (int i=1; i<=n; i++)
    scanf ("%d", &x), theRealAnswer.push_back (x);

vector < int > ans = findSequence (n);
if (ans.size () != theRealAnswer.size ())
{
    printf ("Different lengths\n");
    for (auto it : ans)
        printf ("%d ", it);
    printf ("\n");
    return 0;
}

for (int i=0; i<ans.size (); i++)
    if (ans[i] != theRealAnswer[i])
    {
        printf ("WA position %d\n", i + 1);
        for (auto it : ans)
            printf ("%d ", it);
        printf ("\n");
        return 0;
    }
printf ("Ok, biggest queried length %d\n", maxQ);
return 0;
}
#endif

Compilation message (stderr)

hidden.cpp: In function 'std::vector<int> findSequence(int)':
hidden.cpp:72:1: warning: control reaches end of non-void function [-Wreturn-type]
   72 | }
      | ^
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
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...