답안 #151412

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
151412 2019-09-02T18:52:53 Z AlexPop28 HicCup (FXCUP4_hiccup) C++17
100 / 100
32 ms 8280 KB
#include <bits/stdc++.h>
#include "hiccup.h"

using namespace std;

const int INF = (int)1e9 + 5;

int Solve(int left, int right, const string &s, const vector<int> &lft) {
  if (left > right) {
    return INF;
  }
  if (s[left] == '!') {
    return -1;
  }
  int cnt_excl = 0, cnt_intervals = 0, ans = INF;
  for (int i = right; i >= left; --i) {
    if (s[i] == '!') {
      ++cnt_excl;
    } else {
      assert(s[i] == 'C');
      ++cnt_intervals;
      ans = min({ans, Solve(lft[i] + 1, i - 1, s, lft), cnt_excl / cnt_intervals});
      i = lft[i];
    }
  }
  return ans;
}

int HicCup(string s) {
  int n = s.length();
  vector<int> h_pos, lft(n);
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'H') {
      h_pos.emplace_back(i);
    } else if (s[i] == 'C') {
      if (h_pos.empty()) return -1;
      lft[i] = h_pos.back();
      h_pos.pop_back();
    }
  }
  if (!h_pos.empty()) return -1;
  return Solve(0, n - 1, s, lft);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 31 ms 8184 KB Output is correct
6 Correct 12 ms 8184 KB Output is correct
7 Correct 12 ms 8184 KB Output is correct
8 Correct 32 ms 8184 KB Output is correct
9 Correct 31 ms 8280 KB Output is correct
10 Correct 12 ms 8184 KB Output is correct
11 Correct 2 ms 252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 31 ms 8184 KB Output is correct
6 Correct 12 ms 8184 KB Output is correct
7 Correct 12 ms 8184 KB Output is correct
8 Correct 32 ms 8184 KB Output is correct
9 Correct 31 ms 8280 KB Output is correct
10 Correct 12 ms 8184 KB Output is correct
11 Correct 14 ms 8184 KB Output is correct
12 Correct 13 ms 8184 KB Output is correct
13 Correct 12 ms 8184 KB Output is correct
14 Correct 2 ms 380 KB Output is correct
15 Correct 15 ms 8184 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 3 ms 888 KB Output is correct
19 Correct 16 ms 8148 KB Output is correct
20 Correct 16 ms 8140 KB Output is correct
21 Correct 16 ms 8184 KB Output is correct
22 Correct 15 ms 7672 KB Output is correct
23 Correct 16 ms 8184 KB Output is correct
24 Correct 17 ms 8156 KB Output is correct
25 Correct 30 ms 8140 KB Output is correct
26 Correct 20 ms 8184 KB Output is correct
27 Correct 16 ms 8184 KB Output is correct
28 Correct 15 ms 7976 KB Output is correct
29 Correct 15 ms 8184 KB Output is correct
30 Correct 2 ms 256 KB Output is correct
31 Correct 2 ms 268 KB Output is correct
32 Correct 3 ms 888 KB Output is correct
33 Correct 2 ms 252 KB Output is correct