Submission #254328

#TimeUsernameProblemLanguageResultExecution timeMemory
254328Osama_AlkhodairyHidden Sequence (info1cup18_hidden)C++17
100 / 100
11 ms256 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...