# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
148829 | 2019-09-01T05:12:23 Z | 준표야 함수컵은 캐리해줄거지?(#3588, Acka, spectaclehong, heiler) | HicCup (FXCUP4_hiccup) | C++17 | 256 ms | 7164 KB |
#include "hiccup.h" #include <cstdio> #include <algorithm> using namespace std; int st[1000006] = {-1}; int top; bool chk(string &S, int k) { top = 0; for (int i = 0; i < S.size(); i++) { if (S[i] == 'H') { st[++top] = -1; } else if (S[i] == 'C') { st[++top] = -2; } else if (S[i] == '!') { if (st[top] < 0) st[++top] = 1; else st[top]++; if (st[top - 1] == -1) top--; } if (k) while (top > 2 && st[top - 2] == -1 && st[top - 1] == -2 && st[top] >= k) { st[top - 2] = st[top] - k; top -= 2; while (st[top - 1] >= 0) { st[top - 1] += st[top]; top--; } while (st[top] == 0) top--; } else { while (st[top] >= 0) top--; while (top > 1 && st[top - 1] == -1 && st[top] == -2) top -= 2; } } return !top; } int HicCup(std::string S) { int s = 0; for (int i = 0; i < S.size(); i++) { if (S[i] == 'H') s++; else if (S[i] == 'C') s--; if (s < 0) return -1; if (S[i] == '!' && !s) return -1; } int l = -1, r = S.size(); while (l + 1 < r) { int mid = l + r >> 1; if (!chk(S, mid)) r = mid; else l = mid; } return l; } // int main() { // int ret = HicCup("HHCC!HH!CC"); // printf("%d\n", ret); // }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 384 KB | Output is correct |
2 | Correct | 5 ms | 384 KB | Output is correct |
3 | Correct | 5 ms | 256 KB | Output is correct |
4 | Correct | 11 ms | 640 KB | Output is correct |
5 | Correct | 211 ms | 7164 KB | Output is correct |
6 | Correct | 13 ms | 3200 KB | Output is correct |
7 | Correct | 13 ms | 3328 KB | Output is correct |
8 | Correct | 206 ms | 7032 KB | Output is correct |
9 | Correct | 256 ms | 7160 KB | Output is correct |
10 | Correct | 13 ms | 3328 KB | Output is correct |
11 | Correct | 5 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 384 KB | Output is correct |
2 | Correct | 5 ms | 384 KB | Output is correct |
3 | Correct | 5 ms | 256 KB | Output is correct |
4 | Correct | 11 ms | 640 KB | Output is correct |
5 | Correct | 211 ms | 7164 KB | Output is correct |
6 | Correct | 13 ms | 3200 KB | Output is correct |
7 | Correct | 13 ms | 3328 KB | Output is correct |
8 | Correct | 206 ms | 7032 KB | Output is correct |
9 | Correct | 256 ms | 7160 KB | Output is correct |
10 | Correct | 13 ms | 3328 KB | Output is correct |
11 | Correct | 13 ms | 3376 KB | Output is correct |
12 | Correct | 17 ms | 3328 KB | Output is correct |
13 | Correct | 13 ms | 3328 KB | Output is correct |
14 | Correct | 5 ms | 384 KB | Output is correct |
15 | Correct | 13 ms | 3328 KB | Output is correct |
16 | Correct | 5 ms | 384 KB | Output is correct |
17 | Correct | 6 ms | 384 KB | Output is correct |
18 | Correct | 6 ms | 640 KB | Output is correct |
19 | Incorrect | 13 ms | 3200 KB | Output isn't correct |
20 | Halted | 0 ms | 0 KB | - |