結果

問題 No.252 "良問"(良問とは言っていない (2)
ユーザー simansiman
提出日時 2023-05-08 11:15:12
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 1,351 bytes
コンパイル時間 4,282 ms
コンパイル使用メモリ 141,948 KB
実行使用メモリ 16,020 KB
最終ジャッジ日時 2024-05-03 23:42:51
合計ジャッジ時間 2,722 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
5,248 KB
testcase_01 AC 71 ms
5,248 KB
testcase_02 AC 31 ms
6,036 KB
testcase_03 AC 33 ms
16,020 KB
testcase_04 AC 32 ms
16,008 KB
testcase_05 AC 30 ms
15,996 KB
testcase_06 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  int T;
  cin >> T;

  for (int t = 0; t < T; ++t) {
    string str;
    cin >> str;
    int N = str.size();

    vector<int> good_cnt(N, N);
    vector<int> prob_cnt(N, N);

    for (int i = 0; i < N - 4; ++i) {
      int g_cnt = 0;

      for (int j = 0; j < 4; ++j) {
        int idx = i + j;

        if (str[idx] != "good"[j]) {
          g_cnt++;
        }
      }

      int p_cnt = 0;

      for (int j = 0; j < 7 && i + 6 < N; ++j) {
        int idx = i + j;

        if (str[idx] != "problem"[j]) {
          p_cnt++;
        }
      }

      good_cnt[i] = g_cnt;
      if (i + 6 < N) {
        prob_cnt[i] = p_cnt;
      }
    }

    int min_p_cnt = INT_MAX;
    vector<int> P(N, INT_MAX);
    for (int i = N - 1; i >=0 ; --i) {
      min_p_cnt = min(min_p_cnt, prob_cnt[i]);
      P[i] = min_p_cnt;
    }

    int ans = INT_MAX;
    int found_cnt = 0;

    for (int i = 0; i < N - 4; ++i) {
      int cnt = good_cnt[i] + P[i + 4] + found_cnt;
      ans = min(ans, cnt);

      if (prob_cnt[i] == 0) {
        ++found_cnt;
      }
    }

    cout << ans << endl;
  }

  return 0;
}
0