답안 #997821

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
997821 2024-06-13T00:00:40 Z 12345678 Hidden Sequence (info1cup18_hidden) C++17
0 / 100
51 ms 440 KB
#include<bits/stdc++.h>
#include "grader.h"

using namespace std;

const int nx=205;

int used[nx], sz[nx], mn=-1, a, b;

vector<int> findSequence (int N)
{
    vector<int> tmp, res;
    for (int i=1; i<=(N+1)/2; i++) 
    {
        tmp.push_back(0);
        if (!isSubsequence(tmp))
        {
            mn=0;
            a=i-1;
            break;
        }
    }
    tmp.clear();
    for (int i=1; i<=(N+1)/2; i++)
    {
        tmp.push_back(1);
        if (!isSubsequence(tmp))
        {
            mn=1;
            a=i-1;
            break;
        }
    }
    if (mn==-1) mn=0, a=N/2;
    for (int t=1; t<=200; t++)
    {
        int cnt=0;
        for (int i=0; i<=a; i++) if (!used[i]) cnt++;
        if (cnt==1)
        {
            int sm=0;
            vector<int> res;
            for (int i=0; i<=a; i++) sm+=sz[i];
            for (int i=0; i<=a; i++) if (!used[i]) sz[i]=N-a-sm;
            cnt=0;
        }
        if (cnt==0)
        {
            vector<int> res;
            for (int i=0; i<=a; i++)
            {
                for (int j=0; j<sz[i]; j++) res.push_back(!mn);
                if (i!=a) res.push_back(mn);
            }
            if (res.size()!=N) 
            {
                mn=!mn, a=N-a;
                break;
            }
            return res;
        }
        vector<int> cur;
        for (int i=0; i<=a; i++)
        {
            if (!used[i])
            {
                vector<int> qrs;
                for (int j=0; j<i; j++) if (!used[j]) qrs.push_back(mn);
                for (int j=0; j<t; j++) qrs.push_back(!mn);
                for (int j=i; j<a; j++) if (!used[j]) qrs.push_back(mn);
                //cout<<"query "<<t<<' '<<i<<'\n';
                //for (auto x:qrs) cout<<x<<' ';
                //cout<<'\n';
                if (!isSubsequence(qrs)) cur.push_back(i), sz[i]=t-1;
            }
        }   
        for (auto x:cur) used[x]=1;
    }
    for (int i=0; i<=a; i++) used[i]=0;
    for (int t=1; t<=200; t++)
    {
        int cnt=0;
        for (int i=0; i<=a; i++) if (!used[i]) cnt++;
        if (cnt==1)
        {
            int sm=0;
            vector<int> res;
            for (int i=0; i<=a; i++) sm+=sz[i];
            for (int i=0; i<=a; i++) if (!used[i]) sz[i]=N-a-sm;
            cnt=0;
        }
        if (cnt==0)
        {
            vector<int> res;
            for (int i=0; i<=a; i++)
            {
                for (int j=0; j<sz[i]; j++) res.push_back(!mn);
                if (i!=a) res.push_back(mn);
            }
            if (res.size()!=N) mn=!mn, a=N-a;
            return res;
        }
        vector<int> cur;
        for (int i=0; i<=a; i++)
        {
            if (!used[i])
            {
                vector<int> qrs;
                for (int j=0; j<i; j++) if (!used[j]) qrs.push_back(mn);
                for (int j=0; j<t; j++) qrs.push_back(!mn);
                for (int j=i; j<a; j++) if (!used[j]) qrs.push_back(mn);
                //cout<<"query "<<t<<' '<<i<<'\n';
                //for (auto x:qrs) cout<<x<<' ';
                //cout<<'\n';
                if (!isSubsequence(qrs)) cur.push_back(i), sz[i]=t-1;
            }
        }   
        for (auto x:cur) used[x]=1;
    }
}

Compilation message

hidden.cpp: In function 'std::vector<int> findSequence(int)':
hidden.cpp:55:27: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   55 |             if (res.size()!=N)
      |                 ~~~~~~~~~~^~~
hidden.cpp:100:27: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  100 |             if (res.size()!=N) mn=!mn, a=N-a;
      |                 ~~~~~~~~~~^~~
hidden.cpp:12:17: warning: control reaches end of non-void function [-Wreturn-type]
   12 |     vector<int> tmp, res;
      |                 ^~~
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++)
      |                   ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 344 KB Output is partially correct: Maximum length of a query = 6
2 Incorrect 0 ms 344 KB Output is not correct: The length of the returned sequence is not N
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 51 ms 440 KB Output is not correct: The length of the returned sequence is not N
2 Halted 0 ms 0 KB -