Submission #660868

# Submission time Handle Problem Language Result Execution time Memory
660868 2022-11-23T11:35:13 Z Bagritsevich_Stepan Hidden Sequence (info1cup18_hidden) C++14
100 / 100
72 ms 336 KB
#include <iostream>
#include <vector>
#include "grader.h"

using namespace std;

vector<int> findSequence(const int n) {
    const int maxLength = n / 2 + 1;
    int number = 1;
    vector<int> sequence;
    while (sequence.size() <= maxLength && isSubsequence(sequence)) {
        sequence.push_back(number);
    }
    sequence.pop_back();

    if (sequence.size() == maxLength) {
        number ^= 1;

        sequence.clear();
        while (isSubsequence(sequence)) {
            sequence.push_back(number);
        }
        sequence.pop_back();
    }

    const int countNumbers = (int)sequence.size();
    vector<int> result(n, number ^ 1);

    for (int i = 0; i < countNumbers; i++) {
        while (sequence.size() <= maxLength && isSubsequence(sequence)) {
            sequence.insert(sequence.begin(), number ^ 1);
        }
        sequence.erase(sequence.begin());

        vector<int> reversed_sequence(i + 1, number);
        while (reversed_sequence.size() <= maxLength && isSubsequence(reversed_sequence)) {
            reversed_sequence.push_back(number ^ 1);
        }
        reversed_sequence.pop_back();

        int index = (int)sequence.size() - (countNumbers - i);
        if (reversed_sequence.size() < maxLength) {
            index = n - countNumbers - (reversed_sequence.size() - (i + 1));
        }
        result[index + i] = number;
        sequence.pop_back();
    }

    return result;
}

Compilation message

hidden.cpp: In function 'std::vector<int> findSequence(int)':
hidden.cpp:11:28: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'const int' [-Wsign-compare]
   11 |     while (sequence.size() <= maxLength && isSubsequence(sequence)) {
      |            ~~~~~~~~~~~~~~~~^~~~~~~~~~~~
hidden.cpp:16:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'const int' [-Wsign-compare]
   16 |     if (sequence.size() == maxLength) {
      |         ~~~~~~~~~~~~~~~~^~~~~~~~~~~~
hidden.cpp:30:32: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'const int' [-Wsign-compare]
   30 |         while (sequence.size() <= maxLength && isSubsequence(sequence)) {
      |                ~~~~~~~~~~~~~~~~^~~~~~~~~~~~
hidden.cpp:36:41: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'const int' [-Wsign-compare]
   36 |         while (reversed_sequence.size() <= maxLength && isSubsequence(reversed_sequence)) {
      |                ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
hidden.cpp:42:38: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'const int' [-Wsign-compare]
   42 |         if (reversed_sequence.size() < maxLength) {
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
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 208 KB Output is correct: Maximum length of a query = 5
2 Correct 1 ms 208 KB Output is correct: Maximum length of a query = 6
3 Correct 2 ms 208 KB Output is correct: Maximum length of a query = 5
4 Correct 1 ms 208 KB Output is correct: Maximum length of a query = 5
5 Correct 1 ms 208 KB Output is correct: Maximum length of a query = 4
# Verdict Execution time Memory Grader output
1 Correct 48 ms 300 KB Output is correct: Maximum length of a query = 83
2 Correct 60 ms 296 KB Output is correct: Maximum length of a query = 90
3 Correct 71 ms 300 KB Output is correct: Maximum length of a query = 96
4 Correct 34 ms 336 KB Output is correct: Maximum length of a query = 77
5 Correct 56 ms 300 KB Output is correct: Maximum length of a query = 95
6 Correct 23 ms 292 KB Output is correct: Maximum length of a query = 87
7 Correct 67 ms 296 KB Output is correct: Maximum length of a query = 97
8 Correct 43 ms 328 KB Output is correct: Maximum length of a query = 83
9 Correct 67 ms 304 KB Output is correct: Maximum length of a query = 101
10 Correct 63 ms 296 KB Output is correct: Maximum length of a query = 100
11 Correct 60 ms 300 KB Output is correct: Maximum length of a query = 96
12 Correct 70 ms 308 KB Output is correct: Maximum length of a query = 100
13 Correct 72 ms 208 KB Output is correct: Maximum length of a query = 101