Submission #148876

# Submission time Handle Problem Language Result Execution time Memory
148876 2019-09-01T05:18:05 Z Dopatii(#3751, bogdan10bos, Gioto, Bodo171) HicCup (FXCUP4_hiccup) C++17
Compilation error
0 ms 0 KB
#include "hiccup.h"
#include <bits/stdc++.h>
using namespace std;

int HicCup(std::string S) {
	int N = S.size();
    int nrH = 0, nrC = 0;
    for(auto i : S){
        if(i == '!' && (nrH == 0 || nrC == 0)) return -1;
        else if(i == 'H') ++nrH;
        else if(i == 'C'){
            ++nrC;
            if(nrC > nrH) return -1;
        }
    }
    for(int i = 0; i < N - 1 ; ++i)
        if(S[i] == 'H' && S[i + 1] == '!') return -1;

    for(int i = 0; i < N - 1 ; ++i){
        int nr = 0;
        while(s[i] == 'H') ++nr, ++i;
        if(nr < 2) continue ;

        nr = 0;
        while(s[i] == 'C') ++nr, ++i;
        if(nr >= 2) return 0;
    }

    int st = 0, dr = N;
    while(st <= dr){
        int mij = (st + dr) / 2;

        int nr = 0, f = 0;
        bool ok = true;
        for(int i = N - 1; i >= 0 ; --i){
            if(S[i] == '!') ++nr;
            else if(S[i] == 'C') nr -= mij;

            if(nr < 0) {ok = false; break ;}

        }

        if(ok) st = mij + 1;
        else dr = mij - 1;
    }

	return dr;
}

Compilation message

hiccup.cpp: In function 'int HicCup(std::__cxx11::string)':
hiccup.cpp:21:15: error: 's' was not declared in this scope
         while(s[i] == 'H') ++nr, ++i;
               ^
hiccup.cpp:25:15: error: 's' was not declared in this scope
         while(s[i] == 'C') ++nr, ++i;
               ^
hiccup.cpp:33:21: warning: unused variable 'f' [-Wunused-variable]
         int nr = 0, f = 0;
                     ^