답안 #148976

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
148976 2019-09-01T05:29:17 Z 맞WATLE(#3593, arnold518, ksmzzang2003, songc) HicCup (FXCUP4_hiccup) C++17
100 / 100
82 ms 4352 KB
#include "hiccup.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int N;
string S;

bool decide(int X)
{
    int i, j;

    vector<int> ST;
    for(i=0; i<N; i++)
    {
        if(S[i]=='H') ST.push_back(-1);
        else if(S[i]=='C')
        {
            while(!ST.empty() && ST.back()==0) ST.pop_back();
            if(ST.empty()) return false;
            if(ST.back()!=-1) return false;
            else ST.back()=X;
        }
        else
        {
            if(ST.empty()) return false;
            if(ST.back()==-1) return false;
            if(ST.back()>0) ST.back()--;
            if(ST.size()>1 && ST[ST.size()-1]==0 && ST[ST.size()-2]>=0) ST.pop_back();
        }
    }
    while(!ST.empty() && ST.back()==0) ST.pop_back();
    if(!ST.empty()) return false;
    return true;
}

int HicCup(string _S)
{
    int i, j;
    S=_S; N=S.size();

    int lo=-1, hi=N;
    while(lo+1<hi)
    {
        int mid=lo+hi>>1;
        if(decide(mid)) lo=mid;
        else hi=mid;
    }
    return lo;
}

Compilation message

hiccup.cpp: In function 'bool decide(int)':
hiccup.cpp:14:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
hiccup.cpp: In function 'int HicCup(std::__cxx11::string)':
hiccup.cpp:48:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         int mid=lo+hi>>1;
                 ~~^~~
hiccup.cpp:42:9: warning: unused variable 'i' [-Wunused-variable]
     int i, j;
         ^
hiccup.cpp:42:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 384 KB Output is correct
2 Correct 6 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 24 ms 4352 KB Output is correct
6 Correct 15 ms 4352 KB Output is correct
7 Correct 15 ms 4352 KB Output is correct
8 Correct 25 ms 4352 KB Output is correct
9 Correct 23 ms 4352 KB Output is correct
10 Correct 14 ms 4352 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 384 KB Output is correct
2 Correct 6 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 24 ms 4352 KB Output is correct
6 Correct 15 ms 4352 KB Output is correct
7 Correct 15 ms 4352 KB Output is correct
8 Correct 25 ms 4352 KB Output is correct
9 Correct 23 ms 4352 KB Output is correct
10 Correct 14 ms 4352 KB Output is correct
11 Correct 16 ms 4352 KB Output is correct
12 Correct 16 ms 4352 KB Output is correct
13 Correct 19 ms 4352 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 16 ms 4224 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 6 ms 512 KB Output is correct
19 Correct 34 ms 4352 KB Output is correct
20 Correct 23 ms 4224 KB Output is correct
21 Correct 52 ms 4224 KB Output is correct
22 Correct 54 ms 4096 KB Output is correct
23 Correct 77 ms 4352 KB Output is correct
24 Correct 20 ms 4352 KB Output is correct
25 Correct 23 ms 4352 KB Output is correct
26 Correct 22 ms 4224 KB Output is correct
27 Correct 65 ms 4352 KB Output is correct
28 Correct 76 ms 3968 KB Output is correct
29 Correct 82 ms 4352 KB Output is correct
30 Correct 6 ms 384 KB Output is correct
31 Correct 5 ms 256 KB Output is correct
32 Correct 9 ms 640 KB Output is correct
33 Correct 5 ms 384 KB Output is correct