結果

問題 No.252 "良問"(良問とは言っていない (2)
ユーザー te-shte-sh
提出日時 2017-05-26 14:31:53
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 765 bytes
コンパイル時間 1,439 ms
コンパイル使用メモリ 145,328 KB
実行使用メモリ 16,508 KB
最終ジャッジ日時 2023-09-03 13:37:35
合計ジャッジ時間 4,840 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 305 ms
4,384 KB
testcase_02 AC 403 ms
11,104 KB
testcase_03 AC 405 ms
13,600 KB
testcase_04 AC 402 ms
16,508 KB
testcase_05 AC 403 ms
12,012 KB
testcase_06 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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 = s.indexOf("problem");

  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 = int.max;
  foreach (i; 0..sl-10) {
    if (r > dg[i]) {
      r = dg[i];
      if (fp >= 0 && i > fp) {
        ++r;
      }
    }
  }
  writeln(r);
}

int dist(string s, string t)
{
  return s.zip(t).count!"a[0] != a[1]".to!int;
}
0