#include<bits/stdc++.h>
using namespace std;
#ifndef Graven
#include "grader.h"
#endif
#ifdef Graven
int maxQ=0;
vector<int> F;
bool isSubsequence(const vector<int>& v)
{
if (v.size()>maxQ) maxQ=v.size();
for(int i=0,j=0;i<v.size();++i)
{
while(j<F.size() and v[i]!=F[j]) ++j;
if(j==F.size()) return false;
else ++j;
}
return true;
}
#endif
vector<int> findSequence (int N)
{
if(N<=4)
{
for(int i=0;i<(1<<N);++i)
{
vector<int> wh;
for(int j=0;j<N;++j) wh.push_back((i>>j)&1);
if(isSubsequence(wh)) return wh;
}
}
else
{
vector<int> tmp(N,1),res;
while(!isSubsequence(tmp)) tmp.pop_back();
for(int i=tmp.size(),c0=0;i>=0;--i)
{
while(tmp.size()<N) tmp.push_back(0);
while(!isSubsequence(tmp)) tmp.pop_back();
for(int j=0;j<c0;++j) tmp.pop_back();
while(!tmp.empty() and tmp.back()==0)
{
res.push_back(0);
tmp.pop_back(); ++c0;
}
if(i>0)
{
res.push_back(1);
tmp.pop_back();
}
}
reverse(res.begin(),res.end());
return res;
}
}
#ifdef Graven
int main()
{
int n, x;
scanf ("%d", &n), maxQ = 0;
for (int i=1; i<=n; i++)
scanf ("%d", &x), F.push_back(x);
vector<int> ans=findSequence(n);
if (ans.size () != F.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]!=F[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:55:1: warning: control reaches end of non-void function [-Wreturn-type]
55 | }
| ^
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 time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |