Submission #317173

# Submission time Handle Problem Language Result Execution time Memory
317173 2020-10-29T04:48:40 Z daniel920712 Hidden Sequence (info1cup18_hidden) C++14
64 / 100
8 ms 416 KB
#include<bits/stdc++.h>
#include "grader.h"

using namespace std;
vector < pair < vector < int > , int > > all;
vector < int > temp;
vector < int > tt;
queue < pair < vector < int > , int > > BFS;
vector < int > ans;
vector < int > ans2;
vector < int > ans3;
vector < int > findSequence (int N)
{
    int i,j,ok=0,now=0,x1=0,y1=0,x;
    if(N<=10)
    {
        for(i=0;i<(1<<(N/2+1));i++)
        {
            temp.clear();
            for(j=0;j<(N/2+1);j++)
            {
                if(i&(1<<j)) temp.push_back(1);
                else temp.push_back(0);
            }
            all.push_back(make_pair(temp,isSubsequence(temp)));
        }
        for(i=0;i<(1<<N);i++)
        {
            temp.clear();
            for(j=0;j<N;j++)
            {
                if(i&(1<<j)) temp.push_back(1);
                else temp.push_back(0);
            }
            ok=1;
            for(auto j:all)
            {
                now=0;
                for(auto k:temp)
                {
                    if(now<N/2+1&&k==j.first[now]) now++;
                }
                if(now==N/2+1&&j.second==0) ok=0;
                if(now!=N/2+1&&j.second==1) ok=0;
            }
            if(ok) return temp;
        }
        temp.clear();
        return temp;
    }
    else
    {
        //x=N;
        for(i=0;i<N/2+1;i++)
        {
            temp.push_back(0);
            if(!isSubsequence(temp))
            {
                x=i;
                break;
            }
        }
        temp.clear();
        if(i==N/2+1)
        {
            for(i=0;i<N/2+1;i++)
            {
                temp.push_back(1);
                if(!isSubsequence(temp))
                {
                    x=N-i;
                    break;
                }
            }
        }

        x1=0;
        y1=0;
        while(ans.size()<N/2+1)
        {
            if(x1==x)
            {
                ans.push_back(1);
                y1++;
                continue;
            }
            if(y1==N-x)
            {
                ans.push_back(0);
                x1++;
                continue;
            }

            temp.clear();
            for(auto i:ans) temp.push_back(i);
            if(x-x1<=(N-x-y1))
            {
                temp.push_back(1);
                for(j=x1;j<x;j++) temp.push_back(0);
                if(isSubsequence(temp))
                {
                    y1++;
                    ans.push_back(1);
                }
                else
                {
                    x1++;
                    ans.push_back(0);
                }
            }
            else
            {
                temp.push_back(0);
                for(j=y1;j<N-x;j++) temp.push_back(1);
                if(isSubsequence(temp))
                {
                    x1++;
                    ans.push_back(0);
                }
                else
                {
                    y1++;
                    ans.push_back(1);
                }
            }

        }


        x1=0;
        y1=0;
        while(ans2.size()<N/2+1)
        {
            if(x1==x)
            {
                ans2.insert(ans2.begin(),1);
                y1++;
                continue;
            }
            if(y1==N-x)
            {
                ans2.insert(ans2.begin(),0);
                x1++;
                continue;
            }

            temp.clear();
            for(auto i:ans2) temp.push_back(i);
            if(x-x1<=(N-x-y1))
            {
                temp.insert(temp.begin(),1);
                for(j=x1;j<x;j++) temp.insert(temp.begin(),0);
                if(isSubsequence(temp))
                {
                    y1++;
                    ans2.insert(ans2.begin(),1);
                }
                else
                {
                    x1++;
                    ans2.insert(ans2.begin(),0);
                }
            }
            else
            {
                temp.insert(temp.begin(),0);
                for(j=y1;j<N-x;j++) temp.insert(temp.begin(),1);
                if(isSubsequence(temp))
                {
                    x1++;
                    ans2.insert(ans2.begin(),0);
                }
                else
                {
                    y1++;
                    ans2.insert(ans2.begin(),1);
                }
            }

        }
        for(i=0;i<N;i++) ans3.push_back(0);
        for(i=0;i<ans.size();i++) ans3[i]=ans[i];
        for(i=ans2.size()-1;i>=0;i--) ans3[N-(ans2.size()-i)]=ans2[i];
        return ans3;
    }
}

Compilation message

hidden.cpp: In function 'std::vector<int> findSequence(int)':
hidden.cpp:79:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   79 |         while(ans.size()<N/2+1)
      |               ~~~~~~~~~~^~~~~~
hidden.cpp:132:26: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  132 |         while(ans2.size()<N/2+1)
      |               ~~~~~~~~~~~^~~~~~
hidden.cpp:182:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  182 |         for(i=0;i<ans.size();i++) ans3[i]=ans[i];
      |                 ~^~~~~~~~~~~
hidden.cpp:152:27: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
  152 |                 for(j=x1;j<x;j++) temp.insert(temp.begin(),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 376 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 1 ms 256 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 1 ms 256 KB Output is correct: Maximum length of a query = 4
# Verdict Execution time Memory Grader output
1 Partially correct 6 ms 416 KB Output is partially correct: Maximum length of a query = 123
2 Partially correct 8 ms 256 KB Output is partially correct: Maximum length of a query = 133
3 Partially correct 6 ms 256 KB Output is partially correct: Maximum length of a query = 141
4 Partially correct 8 ms 256 KB Output is partially correct: Maximum length of a query = 111
5 Partially correct 8 ms 256 KB Output is partially correct: Maximum length of a query = 138
6 Partially correct 6 ms 256 KB Output is partially correct: Maximum length of a query = 109
7 Partially correct 6 ms 256 KB Output is partially correct: Maximum length of a query = 145
8 Partially correct 4 ms 372 KB Output is partially correct: Maximum length of a query = 113
9 Partially correct 7 ms 256 KB Output is partially correct: Maximum length of a query = 148
10 Partially correct 7 ms 256 KB Output is partially correct: Maximum length of a query = 147
11 Partially correct 6 ms 256 KB Output is partially correct: Maximum length of a query = 143
12 Partially correct 7 ms 256 KB Output is partially correct: Maximum length of a query = 150
13 Partially correct 8 ms 256 KB Output is partially correct: Maximum length of a query = 151