# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
613043 | 2022-07-30T03:04:17 Z | penguinhacker | HicCup (FXCUP4_hiccup) | C++17 | 0 ms | 0 KB |
#include "hiccup.h" #include <bits/stdc++.h> using namespace std; const int mxN=1e6+2; int n=1, cnt[mxN]; stack<int> stk; vector<int> adj[mxN]; /*bool dfs(int u, int x) { for (int v : adj[u]) if (!dfs(v, x)) return 0; reverse(adj[u].begin(), adj[u].end()); int cur=0; for (int i=0; i<adj[u].size(); ++i) { cur+=cnt[adj[u][i]]-x; if (cur<0) return 0; } reverse(adj[u].begin(), adj[u].end()); return 1; }*/ int HicCup(string s) { stk.push(0); for (int i=0; i<s.size(); ++i) { if (s[i]=='H') { adj[stk.top()].push_back(n2); stk.push(n2++); } else if (s[i]=='C') { stk.pop(); if (stk.empty()) return -1; } else { if (!i||s[i-1]=='H') return -1; ++cnt[stk.top()]; } } return -1; /*if (stk.size()!=1) return -1; int lb=0, rb=1e6; while(lb<rb) { int mid=(lb+rb+1)/2; if (dfs(0, mid)) lb=mid; else rb=mid-1; } return lb;*/ }