Submission #44743

# Submission time Handle Problem Language Result Execution time Memory
44743 2018-04-06T03:15:21 Z model_code Hidden Sequence (info1cup18_hidden) C++17
100 / 100
102 ms 692 KB
#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;
}

Compilation message

grader.cpp: In function 'int main()':
grader.cpp:28:43: warning: format '%d' expects argument of type 'int', but argument 3 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
     fprintf (fifo_out, "%d\n", ans.size ());
                                ~~~~~~~~~~~^
grader.cpp:29:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0; i<ans.size () && i < N; i++)
                   ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct: Maximum length of a query = 5
2 Correct 2 ms 308 KB Output is correct: Maximum length of a query = 6
3 Correct 2 ms 384 KB Output is correct: Maximum length of a query = 5
4 Correct 2 ms 588 KB Output is correct: Maximum length of a query = 5
5 Correct 2 ms 588 KB Output is correct: Maximum length of a query = 4
# Verdict Execution time Memory Grader output
1 Correct 36 ms 588 KB Output is correct: Maximum length of a query = 83
2 Correct 28 ms 588 KB Output is correct: Maximum length of a query = 90
3 Correct 19 ms 588 KB Output is correct: Maximum length of a query = 96
4 Correct 19 ms 588 KB Output is correct: Maximum length of a query = 77
5 Correct 13 ms 588 KB Output is correct: Maximum length of a query = 95
6 Correct 5 ms 588 KB Output is correct: Maximum length of a query = 87
7 Correct 23 ms 692 KB Output is correct: Maximum length of a query = 97
8 Correct 19 ms 692 KB Output is correct: Maximum length of a query = 83
9 Correct 54 ms 692 KB Output is correct: Maximum length of a query = 101
10 Correct 102 ms 692 KB Output is correct: Maximum length of a query = 100
11 Correct 9 ms 692 KB Output is correct: Maximum length of a query = 96
12 Correct 9 ms 692 KB Output is correct: Maximum length of a query = 100
13 Correct 38 ms 692 KB Output is correct: Maximum length of a query = 101