답안 #151621

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
151621 2019-09-03T21:46:04 Z thebes HicCup (FXCUP4_hiccup) C++17
100 / 100
202 ms 4344 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

const int MN = 1e6+6;
int lo, hi, i, f, g;
stack<int> st;
stack<char> ch;

int HicCup(string s){
    lo = 0, hi = s.size();
    while(lo<hi){
        int m = (lo+hi)/2;
        f = 0; g = 1;
        while(st.size()) st.pop();
        while(ch.size()) ch.pop();
        for(i=0;i<s.size();i++){
            if(s[i]=='H'){
                f = 0;
                st.push(0);
                ch.push('H');
            }
            else if(s[i]=='C'){
                if(ch.empty()||ch.top()!='H'){
                    g = 0;
                    break;
                }
                ch.pop();
                ch.push('C');
                if(m==0){
                    ch.pop();
                    st.pop();
                    f = 1;
                }
            }
            else if(s[i]=='!'){
                if(ch.empty()&&f) continue;
                else if(ch.empty()){g=0; break;}
                if(ch.top()=='H'&&!f){g=0; break;}
                else if(ch.top()=='H'&&f) continue;
                ch.pop();
                ch.push('!');
                st.top()++;
                if(st.top()==m){
                    f = 1;
                    st.pop();
                    ch.pop();
                }
            }
        }
        if(!g||ch.size()) hi=m;
        else lo=m+1;
    }
    return lo-1;
}

Compilation message

hiccup.cpp: In function 'int HicCup(std::__cxx11::string)':
hiccup.cpp:20:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(i=0;i<s.size();i++){
                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 380 KB Output is correct
5 Correct 23 ms 3320 KB Output is correct
6 Correct 9 ms 3320 KB Output is correct
7 Correct 9 ms 3220 KB Output is correct
8 Correct 24 ms 3320 KB Output is correct
9 Correct 23 ms 3320 KB Output is correct
10 Correct 9 ms 3320 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 380 KB Output is correct
5 Correct 23 ms 3320 KB Output is correct
6 Correct 9 ms 3320 KB Output is correct
7 Correct 9 ms 3220 KB Output is correct
8 Correct 24 ms 3320 KB Output is correct
9 Correct 23 ms 3320 KB Output is correct
10 Correct 9 ms 3320 KB Output is correct
11 Correct 11 ms 3192 KB Output is correct
12 Correct 16 ms 3320 KB Output is correct
13 Correct 20 ms 3320 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 11 ms 3312 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 3 ms 504 KB Output is correct
19 Correct 54 ms 3192 KB Output is correct
20 Correct 22 ms 4212 KB Output is correct
21 Correct 114 ms 4216 KB Output is correct
22 Correct 126 ms 4088 KB Output is correct
23 Correct 202 ms 4344 KB Output is correct
24 Correct 15 ms 4216 KB Output is correct
25 Correct 23 ms 4328 KB Output is correct
26 Correct 17 ms 4172 KB Output is correct
27 Correct 132 ms 4300 KB Output is correct
28 Correct 202 ms 4180 KB Output is correct
29 Correct 196 ms 4344 KB Output is correct
30 Correct 2 ms 380 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 13 ms 632 KB Output is correct
33 Correct 2 ms 376 KB Output is correct