답안 #96483

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
96483 2019-02-09T16:08:16 Z ASG1065 Hidden Sequence (info1cup18_hidden) C++14
100 / 100
11 ms 376 KB
#include<bits/stdc++.h>
#include "grader.h"

std::vector <int> findSequence(int n)
{
    std::vector <int> ans;
    std::vector <int> ones;
    std::vector<int> zeros;
    int zeroct;
    int onect;
    for (int i = 1; i <= std::floor(n/2)+1; ++i)
    {
        zeros.push_back(0);
        if (!isSubsequence(zeros))
        {
            zeroct=i-1;
            onect=n-zeroct;
            break;
        }
        ones.push_back(1);
        if (!isSubsequence(ones))
        {
            onect=i-1;
            zeroct=n-onect;
            break;
        }
    }
    int usedzeros = 0;
    int usedones = 0;
    for (int i = 0; i < n; ++i)
    {
        std::vector<int> guess;
        if (usedzeros+1+onect-usedones <= usedones+1+zeroct-usedzeros)
        {
            for (int j = 0; j < usedzeros+1; ++j)
            {
                guess.push_back(0);
            }
            for (int j = 0; j < onect-usedones; ++j)
            {
                guess.push_back(1);
            }
            if (isSubsequence(guess))
            {
                ans.push_back(0);
                ++usedzeros;
            }
            else
            {
                ans.push_back(1);
                ++usedones;
            }
        }
        else
        {
            for (int j = 0; j < usedones+1; ++j)
            {
                guess.push_back(1);
            }
            for (int j = 0; j < zeroct-usedzeros; ++j)
            {
                guess.push_back(0);
            }
            if (isSubsequence(guess))
            {
                ans.push_back(1);
                ++usedones;
            }
            else
            {
                ans.push_back(0);
                ++usedzeros;
            }
        }
    }
    return ans;
}

Compilation message

hidden.cpp: In function 'std::vector<int> findSequence(int)':
hidden.cpp:33:24: warning: 'onect' may be used uninitialized in this function [-Wmaybe-uninitialized]
         if (usedzeros+1+onect-usedones <= usedones+1+zeroct-usedzeros)
             ~~~~~~~~~~~^~~~~~
hidden.cpp:33:53: warning: 'zeroct' may be used uninitialized in this function [-Wmaybe-uninitialized]
         if (usedzeros+1+onect-usedones <= usedones+1+zeroct-usedzeros)
                                           ~~~~~~~~~~^~~~~~~
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++)
                   ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 252 KB Output is correct: Maximum length of a query = 5
2 Correct 2 ms 376 KB Output is correct: Maximum length of a query = 6
3 Correct 2 ms 376 KB Output is correct: Maximum length of a query = 5
4 Correct 2 ms 292 KB Output is correct: Maximum length of a query = 5
5 Correct 2 ms 248 KB Output is correct: Maximum length of a query = 4
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 316 KB Output is correct: Maximum length of a query = 83
2 Correct 8 ms 248 KB Output is correct: Maximum length of a query = 90
3 Correct 10 ms 376 KB Output is correct: Maximum length of a query = 96
4 Correct 6 ms 248 KB Output is correct: Maximum length of a query = 77
5 Correct 9 ms 376 KB Output is correct: Maximum length of a query = 95
6 Correct 7 ms 376 KB Output is correct: Maximum length of a query = 87
7 Correct 8 ms 376 KB Output is correct: Maximum length of a query = 97
8 Correct 4 ms 316 KB Output is correct: Maximum length of a query = 83
9 Correct 9 ms 376 KB Output is correct: Maximum length of a query = 101
10 Correct 6 ms 312 KB Output is correct: Maximum length of a query = 100
11 Correct 5 ms 312 KB Output is correct: Maximum length of a query = 96
12 Correct 11 ms 320 KB Output is correct: Maximum length of a query = 100
13 Correct 9 ms 316 KB Output is correct: Maximum length of a query = 101