# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
151540 | 2019-09-03T14:06:07 Z | leduykhongngu | HicCup (FXCUP4_hiccup) | C++17 | 12 ms | 760 KB |
#include <cstdio> #include <iostream> #include <cstring> #include <stack> using namespace std; string S = ""; int n; bool Check(int x) { stack<char> st; stack<int> cnt; int cur = 0; bool chk = true; for (int i = 0; i < n; ++i) { if (S[i] != '!') { st.push(S[i]); if(cur) cnt.push(cur); cur = 0; } else { if (chk) return false; if (st.size() && st.top() != 'H') { ++cur; st.push(S[i]); } } if (cur == x) { // for (int i = 1; i <= x; ++i) // if (st.top() == '!') st.pop(); // else return false; while (st.size() && st.top() == '!') st.pop(); if (st.size() && st.top() == 'C') st.pop(); else return false; if (st.size() && st.top() == 'H') st.pop(); else return false; if (cnt.empty()) cur = 0; else { cur = cnt.top(); cnt.pop(); } } chk = !((S[i] == 'C') || (S[i] == '!')); } return st.empty(); } int HicCup(std::string tmp) { for (int i = 0; i < tmp.length(); ++i) { S.push_back(tmp[i]); if (tmp[i] == 'C') S.push_back('!'); } n = S.length(); // cout << Check(1); // for (int i = 1; i <= 1; ++i) // cout << Check(i) << endl; int lef = 0, rig = n, ans = -1; while (lef <= rig) { int mid = (lef + rig)/2; if (Check(mid)) { ans = max(ans, mid); lef = mid + 1; } else rig = mid - 1; } if (ans != -1) --ans; return ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 252 KB | Output is correct |
2 | Correct | 2 ms | 256 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Incorrect | 12 ms | 760 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 252 KB | Output is correct |
2 | Correct | 2 ms | 256 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Incorrect | 12 ms | 760 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |