Submission #895342

# Submission time Handle Problem Language Result Execution time Memory
895342 2023-12-29T19:10:43 Z borisAngelov Hidden Sequence (info1cup18_hidden) C++17
100 / 100
3 ms 692 KB
#include<bits/stdc++.h>
#include "grader.h"

using namespace std;

int countDigits(int digit, int n)
{
    vector<int> v;
    v.push_back(digit);

    int cnt = 1;

    while (cnt <= n)
    {
        if (isSubsequence(v) == false)
        {
            return cnt - 1;
        }

        v.push_back(digit);

        ++cnt;
    }

    return n;
}

vector<int> findSequence(int n)
{
    if (n == 1)
    {
        if (isSubsequence({0}) == true)
        {
            return {0};
        }
        else
        {
            return {1};
        }
    }

    int cnt0 = 0;
    int cnt1 = 0;

    vector<int> digits;

    for (int j = 1; j <= n / 2 + 1; ++j)
    {
        digits.push_back(0);
    }

    if (isSubsequence(digits) == true)
    {
        cnt1 = countDigits(1, n);
        cnt0 = n - cnt1;
    }
    else
    {
        cnt0 = countDigits(0, n);
        cnt1 = n - cnt0;
    }

    vector<int> sequence;

    int pref0 = 0;
    int pref1 = 0;

    for (int i = 0; i < n; ++i)
    {
        if (cnt0 == 0)
        {
            sequence.push_back(1);
            continue;
        }

        if (cnt1 == 0)
        {
            sequence.push_back(0);
            continue;
        }

        if (pref0 + 1 + (cnt1 - pref1) < pref1 + 1 + (cnt0 - pref0))
        {
            vector<int> curr;

            for (int j = 1; j <= pref0 + 1; ++j)
            {
                curr.push_back(0);
            }

            for (int j = 1; j <= cnt1 - pref1; ++j)
            {
                curr.push_back(1);
            }

            if (isSubsequence(curr) == true)
            {
                sequence.push_back(0);
                ++pref0;
            }
            else
            {
                sequence.push_back(1);
                ++pref1;
            }
        }
        else
        {
            vector<int> curr;

            for (int j = 1; j <= pref1 + 1; ++j)
            {
                curr.push_back(1);
            }

            for (int j = 1; j <= cnt0 - pref0; ++j)
            {
                curr.push_back(0);
            }

            if (isSubsequence(curr) == true)
            {
                sequence.push_back(1);
                ++pref1;
            }
            else
            {
                sequence.push_back(0);
                ++pref0;
            }
        }
    }

    return sequence;
}

Compilation message

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 0 ms 344 KB Output is correct: Maximum length of a query = 5
2 Correct 1 ms 344 KB Output is correct: Maximum length of a query = 6
3 Correct 0 ms 344 KB Output is correct: Maximum length of a query = 5
4 Correct 0 ms 344 KB Output is correct: Maximum length of a query = 5
5 Correct 0 ms 356 KB Output is correct: Maximum length of a query = 4
# Verdict Execution time Memory Grader output
1 Correct 2 ms 440 KB Output is correct: Maximum length of a query = 83
2 Correct 2 ms 692 KB Output is correct: Maximum length of a query = 90
3 Correct 3 ms 440 KB Output is correct: Maximum length of a query = 96
4 Correct 2 ms 692 KB Output is correct: Maximum length of a query = 77
5 Correct 3 ms 436 KB Output is correct: Maximum length of a query = 95
6 Correct 2 ms 688 KB Output is correct: Maximum length of a query = 87
7 Correct 3 ms 432 KB Output is correct: Maximum length of a query = 97
8 Correct 2 ms 692 KB Output is correct: Maximum length of a query = 83
9 Correct 3 ms 440 KB Output is correct: Maximum length of a query = 101
10 Correct 3 ms 436 KB Output is correct: Maximum length of a query = 100
11 Correct 3 ms 436 KB Output is correct: Maximum length of a query = 96
12 Correct 3 ms 432 KB Output is correct: Maximum length of a query = 100
13 Correct 3 ms 440 KB Output is correct: Maximum length of a query = 101