結果

問題 No.150 "良問"(良問とは言っていない
ユーザー te-sh
提出日時 2017-02-02 12:24:56
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 88 ms / 5,000 ms
コード長 528 bytes
コンパイル時間 951 ms
コンパイル使用メモリ 135,428 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-12 06:51:36
合計ジャッジ時間 1,868 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto t = readln.chomp.to!size_t;

  foreach (_; t.iota) {
    auto s = readln.chomp;

    auto mi = int.max;
    foreach (i; 0..s.length-10) {
      auto hg = hammingDistance(s[i..i+4], "good");
      foreach (j; i+4..s.length-6) {
        auto hp = hammingDistance(s[j..j+7], "problem");
        mi = min(mi, hg + hp);
      }
    }

    writeln(mi);
  }
}

auto hammingDistance(string a, string b)
{
  return zip(a, b).count!"a[0] != a[1]";
}
0