제출 #150570

#제출 시각아이디문제언어결과실행 시간메모리
150570GucciBelt (#200)HicCup (FXCUP4_hiccup)C++17
24 / 100
209 ms12392 KiB
#include "hiccup.h" #include <bits/stdc++.h> #define pii pair<int, int> #define x first #define y second using namespace std; const int N = 1e6+5; int n, lvl[N]; bool checkFunction(string str, int mid) { stack<pii> stk; for(int i = 0; i < n; ++i) { if(str[i] == 'C') stk.emplace(0, lvl[i]); if(str[i] == '!') { if(stk.empty()) continue; if(stk.top().y != lvl[i]) continue; pii v = stk.top(); stk.pop(); if(++v.x == mid) continue; stk.emplace(v); } } return stk.empty(); } int HicCup(string S) { n = S.size(); int cnt = 0, pv = -1; for(int i = 0; i < n; ++i) { if(S[i] == 'H') cnt++, pv = -1; if(S[i] == 'C') { lvl[i] = cnt; if(!~--cnt) return -1; else pv = i; } if(S[i] == '!') { if(pv == -1) return -1; else lvl[i] = lvl[pv]; } } if(cnt) return -1; int l = 0, r = S.size(); while(l < r) { int mid = (l + r + 1) >> 1; if(checkFunction(S, mid)) l = mid; else r = mid-1; } return l; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...