# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
613044 | 2022-07-30T03:05:06 Z | penguinhacker | HicCup (FXCUP4_hiccup) | C++17 | 69 ms | 34812 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(n); stk.push(n++); } else if (s[i]=='C') { stk.pop(); if (stk.empty()) return -1; } else { if (!i||s[i-1]=='H') return -1; ++cnt[stk.top()]; } } 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; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 18 ms | 23784 KB | Output is correct |
2 | Correct | 20 ms | 23756 KB | Output is correct |
3 | Correct | 20 ms | 23768 KB | Output is correct |
4 | Correct | 19 ms | 24148 KB | Output is correct |
5 | Correct | 63 ms | 34812 KB | Output is correct |
6 | Correct | 34 ms | 26660 KB | Output is correct |
7 | Correct | 21 ms | 26696 KB | Output is correct |
8 | Correct | 63 ms | 34812 KB | Output is correct |
9 | Correct | 69 ms | 34736 KB | Output is correct |
10 | Correct | 20 ms | 26652 KB | Output is correct |
11 | Correct | 12 ms | 23792 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 18 ms | 23784 KB | Output is correct |
2 | Correct | 20 ms | 23756 KB | Output is correct |
3 | Correct | 20 ms | 23768 KB | Output is correct |
4 | Correct | 19 ms | 24148 KB | Output is correct |
5 | Correct | 63 ms | 34812 KB | Output is correct |
6 | Correct | 34 ms | 26660 KB | Output is correct |
7 | Correct | 21 ms | 26696 KB | Output is correct |
8 | Correct | 63 ms | 34812 KB | Output is correct |
9 | Correct | 69 ms | 34736 KB | Output is correct |
10 | Correct | 20 ms | 26652 KB | Output is correct |
11 | Correct | 12 ms | 23792 KB | Output is correct |
12 | Correct | 23 ms | 27840 KB | Output is correct |
13 | Correct | 26 ms | 27096 KB | Output is correct |
14 | Correct | 21 ms | 26684 KB | Output is correct |
15 | Correct | 13 ms | 23704 KB | Output is correct |
16 | Correct | 22 ms | 26680 KB | Output is correct |
17 | Correct | 14 ms | 23764 KB | Output is correct |
18 | Correct | 16 ms | 23812 KB | Output is correct |
19 | Correct | 15 ms | 24056 KB | Output is correct |
20 | Incorrect | 27 ms | 26956 KB | Output isn't correct |
21 | Halted | 0 ms | 0 KB | - |