結果
| 問題 | No.252 "良問"(良問とは言っていない (2) | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2017-05-26 15:20:16 | 
| 言語 | D (dmd 2.109.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 416 ms / 2,000 ms | 
| コード長 | 803 bytes | 
| コンパイル時間 | 895 ms | 
| コンパイル使用メモリ | 138,160 KB | 
| 実行使用メモリ | 16,668 KB | 
| 最終ジャッジ日時 | 2024-06-12 19:27:32 | 
| 合計ジャッジ時間 | 4,330 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 7 | 
ソースコード
import std.algorithm, std.conv, std.range, std.stdio, std.string;
void main()
{
  auto t = readln.chomp.to!size_t;
  foreach (_; 0..t) calc();
}
void calc()
{
  auto s = readln.chomp, sl = s.length;
  auto dg = new int[](sl-10), dp = new int[](sl-10);
  foreach (i; 0..sl-10) {
    dg[i] = dist(s[i..i+4], "good");
    dp[i] = dist(s[i+4..i+11], "problem");
  }
  auto fp = new int[](sl-6);
  foreach (i; 0..sl-6)
    fp[i] = s[i..i+7] == "problem" ? 1 : 0;
  foreach (i; 1..sl-6)
    fp[i] += fp[i-1];
  foreach (i; 1..sl-10) {
    dg[i] = min(dg[i-1], dg[i]);
    dp[$-i-1] = min(dp[$-i], dp[$-i-1]);
  }
  dg[] += dp[];
  auto r = dg[0];
  foreach (i; 1..sl-10)
    r = min(r, dg[i] + fp[i-1]);
  writeln(r);
}
int dist(string s, string t)
{
  return s.zip(t).count!"a[0] != a[1]".to!int;
}
            
            
            
        