답안 #148885

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
148885 2019-09-01T05:19:09 Z Dopatii(#3751, bogdan10bos, Gioto, Bodo171) HicCup (FXCUP4_hiccup) C++17
0 / 100
26 ms 3328 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 ; ++i){
        int nr = 0;
        while(i < N && S[i] == 'H') ++nr, ++i;
        if(nr < 2) continue ;

        nr = 0;
        while(i < N && 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:33:21: warning: unused variable 'f' [-Wunused-variable]
         int nr = 0, f = 0;
                     ^
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 6 ms 512 KB Output is correct
5 Correct 26 ms 3328 KB Output is correct
6 Correct 13 ms 3200 KB Output is correct
7 Correct 13 ms 3328 KB Output is correct
8 Correct 26 ms 3328 KB Output is correct
9 Correct 26 ms 3328 KB Output is correct
10 Correct 13 ms 3200 KB Output is correct
11 Incorrect 5 ms 384 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 6 ms 512 KB Output is correct
5 Correct 26 ms 3328 KB Output is correct
6 Correct 13 ms 3200 KB Output is correct
7 Correct 13 ms 3328 KB Output is correct
8 Correct 26 ms 3328 KB Output is correct
9 Correct 26 ms 3328 KB Output is correct
10 Correct 13 ms 3200 KB Output is correct
11 Correct 14 ms 3328 KB Output is correct
12 Correct 14 ms 3328 KB Output is correct
13 Correct 13 ms 3328 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 14 ms 3200 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 6 ms 384 KB Output is correct
18 Correct 6 ms 640 KB Output is correct
19 Correct 19 ms 3328 KB Output is correct
20 Incorrect 22 ms 3328 KB Output isn't correct
21 Halted 0 ms 0 KB -