Submission #1174877

#TimeUsernameProblemLanguageResultExecution timeMemory
1174877browntoadHidden Sequence (info1cup18_hidden)C++20
100 / 100
49 ms416 KiB
#include <bits/stdc++.h>
#include "grader.h"
using namespace std;
#define ll long long
// #define int ll
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n+1)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define pii pair<int, int>
#define pip pair<int, pii>
#define f first
#define s second
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)((x).size())

#ifdef TOAD
#define IOS() ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#else
#define IOS() ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#endif // TOAD

const ll maxn = 1e3+5;
const int iinf = 1e9+5;

vector<int> findSequence(int n){
    int n0 = -1, n1 = -1;
    vector<int> tmp;
    while(1){
        tmp.pb(0);
        if (!isSubsequence(tmp)){
            tmp.pop_back();
            n0 = SZ(tmp);
            break;
        }
        if (SZ(tmp) == n/2+1){
            break;
        }
    }
    if (n0 != -1){
        n1 = n-n0;
    }
    else{
        tmp.clear();
        while(1){
            tmp.pb(1);
            if (!isSubsequence(tmp)){
                tmp.pop_back();
                n1 = SZ(tmp);
                break;
            }
            if (SZ(tmp) == n/2+1){
                break;
            }
        }
        n0 = n-n1;
    }

    vector<int> ret;
    if (n0 == 0){
        REP(i, n) ret.pb(1);
        return ret;
    }
    if (n0 == n){
        REP(i, n) ret.pb(0);
        return ret;
    }

    ret = vector<int> (n);
    fill(ALL(ret), 1); // default: 1
    REP(i, n0){
        // attempt 1
        int pos = -1;
        tmp.clear();
        REP(j, i+1) tmp.pb(0);

        while(1){
            tmp.pb(1);
            if (SZ(tmp) > n/2+1){
                break;
            }
            if (!isSubsequence(tmp)){
                tmp.pop_back();
                pos = n - ((SZ(tmp) - i - 1) + (n0 - i - 1)) - 1;
                ret[pos] = 0;
                break;
            }
        }
        if (pos == -1){ // attempt 2
            tmp.clear();
            REP(j, n0-i) tmp.pb(0);

            while(1){
                tmp.insert(tmp.begin(), 1);
                if (SZ(tmp) > n/2+1){
                    break;
                }
                if (!isSubsequence(tmp)){
                    tmp.pop_back();
                    pos = (SZ(tmp) - (n0-i)) + i;
                    ret[pos] = 0;
                    break;
                }
            }
        }
        if (pos == -1){ // special case, where a+b and c+d all equal to ceil(n/2), n is odd: ez
            pos = (n/2+1 - (n0-i)) + i; // a+b has to equal to n/2+1
            ret[pos] = 0;
        }
    }
    return ret;
}
/*
special case: 0 1 0 1 0 type shit
*/
/*
signed main(){
    IOS();
    int n; cin>>n;
}
*/
/*
2 3
2 4 3
5 7 5
*/


Compilation message (stderr)

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