Submission #254328

# Submission time Handle Problem Language Result Execution time Memory
254328 2020-07-29T21:10:28 Z Osama_Alkhodairy Hidden Sequence (info1cup18_hidden) C++17
100 / 100
11 ms 256 KB
#include <bits/stdc++.h>
#include "grader.h"
//~ #include "grader.cpp"
using namespace std;

int n;

vector <int> compress(vector <int> &a){
    vector <int> ret;
    int n = a.size();
    int cur = -1;
    while(cur < n - 1){
        int x = cur + 1, y = cur + 1;
        while(x < n && a[x] != 0) x++;
        while(y < n && a[y] != 1) y++;
        assert(x < n || y < n);
        if(y == n || (x < n && x > y)){
            assert(x < n);
            ret.push_back(0);
            cur = x;
        }
        else{
            ret.push_back(1);
            cur = y;
        }
    }
    return ret;
}
vector <int> findSequence(int N){
    n = N;
    vector <int> ones, zeros;
    int z = 0, o = 0;
    while(true){
        ones.push_back(1);
        zeros.push_back(0);
        if(isSubsequence(zeros) == 0){
            z = zeros.size() - 1;
            o = n - z;
            break;
        }
        if(isSubsequence(ones) == 0){
            o = ones.size() - 1;
            z = n - o;
            break;
        }
    }
    vector <int> a;
    while((int)a.size() < n){
        if(z == 0){
            a.push_back(1);
            continue;
        }
        if(o == 0){
            a.push_back(0);
            continue;
        }
        vector <int> g = a;
        g.push_back(0);
        g = compress(g);
        for(int j = 0 ; j < o ; j++){
            g.push_back(1);
        }
        vector <int> h = a;
        h.push_back(1);
        h = compress(h);
        for(int j = 0 ; j < z ; j++){
            h.push_back(0);
        }
        int c;
        if(g.size() < h.size()){
            if(isSubsequence(g)) c = 0;
            else c = 1;
        }
        else{
            if(isSubsequence(h)) c = 1;
            else c = 0;
        }
        a.push_back(c);
        if(c == 0) z--;
        else o--;
    }
    return a;
}

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