Submission #660867

# Submission time Handle Problem Language Result Execution time Memory
660867 2022-11-23T11:31:54 Z Bagritsevich_Stepan Hidden Sequence (info1cup18_hidden) C++14
100 / 100
74 ms 416 KB
#include <iostream>
#include <vector>
#include "grader.h"

using namespace std;

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

    if (sequence.size() == maxlen) {
        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() <= maxlen && isSubsequence(sequence)) {
            sequence.insert(sequence.begin(), number ^ 1);
        }
        sequence.erase(sequence.begin());

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

        int index = (int)sequence.size() - (countNumbers - i);
        if (reversed_sequence.size() < maxlen) {
            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() <= maxlen && 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() == maxlen) {
      |         ~~~~~~~~~~~~~~~~^~~~~~~~~
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() <= maxlen && 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() <= maxlen && 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() < maxlen) {
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
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 2 ms 288 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 1 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 47 ms 304 KB Output is correct: Maximum length of a query = 83
2 Correct 53 ms 312 KB Output is correct: Maximum length of a query = 90
3 Correct 63 ms 300 KB Output is correct: Maximum length of a query = 96
4 Correct 43 ms 208 KB Output is correct: Maximum length of a query = 77
5 Correct 63 ms 416 KB Output is correct: Maximum length of a query = 95
6 Correct 26 ms 284 KB Output is correct: Maximum length of a query = 87
7 Correct 57 ms 208 KB Output is correct: Maximum length of a query = 97
8 Correct 47 ms 284 KB Output is correct: Maximum length of a query = 83
9 Correct 67 ms 208 KB Output is correct: Maximum length of a query = 101
10 Correct 59 ms 308 KB Output is correct: Maximum length of a query = 100
11 Correct 67 ms 296 KB Output is correct: Maximum length of a query = 96
12 Correct 66 ms 304 KB Output is correct: Maximum length of a query = 100
13 Correct 74 ms 300 KB Output is correct: Maximum length of a query = 101