제출 #1151436

#제출 시각아이디문제언어결과실행 시간메모리
1151436thunoproHidden Sequence (info1cup18_hidden)C++20
100 / 100
22 ms436 KiB
#include<bits/stdc++.h>

using namespace std;

bool isSubsequence (vector < int > v);

bool ask (int bg, int pf, int sf)
{
    vector < int > curr;
    while (pf --)
        curr.push_back (bg);
    bg ^= 1;
    while (sf --)
        curr.push_back (bg);
    return isSubsequence (curr);
}

vector < int > findSequence (int N)
{
    int lim = N / 2 + 1, K = -1, leastFrequent = -1;///we want to fit this limit and we will
    int s[5000];
    for (int minL = 0; minL <= N / 2;  minL ++)
    {
        if (ask (0, minL + 1, 0) == 0)
        {
            K = minL;
            leastFrequent = 0;
            break;
        }
        if (ask (1, minL + 1, 0) == 0)
        {
            K = minL;
            leastFrequent = 1;
            break;
        }
    }
    assert (K != -1 && leastFrequent != -1);
    s[K + 1] = N - K, s[0] = 0;
    for (int i=1; i<=K; i++)
    {
        s[i] = s[i - 1];
        bool q = 1;
        while (s[i] + K + 1 - i <= lim)
        {
            q = ask (leastFrequent ^ 1, s[i], K + 1 - i);
            if (q == 0)
            {
                s[i] --;
                break;
            }
            s[i] ++;
        }
        if (q == 0) continue;///found it without reversing
        int opS = 0;
        while (opS + i <= lim)
        {
            q = ask (leastFrequent, i, opS);
            if (q == 0)
            {
                opS --;
                break;
            }
            opS ++;
        }
        if (q == 0) s[i] = N - K - opS;
        else opS --, s[i] = N - K - opS;///in this case I'm right at half of it, and couldn't afford asking one more query
        ///the answer to that query, however, should've been negative anyways, so there's no problem actually
    }
    for (int i=K + 1; i>=1; i--)
        s[i] -= s[i - 1];
    vector < int > ans;
    for (int i=1; i<=K + 1; i++)
    {
        while (s[i] --)
            ans.push_back (leastFrequent ^ 1);
        if (i != K + 1) ans.push_back (leastFrequent);
    }
    return ans;
}

컴파일 시 표준 에러 (stderr) 메시지

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...