結果

問題 No.150 "良問"(良問とは言っていない
ユーザー te-sh
提出日時 2016-08-31 00:54:32
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 93 ms / 5,000 ms
コード長 686 bytes
コンパイル時間 869 ms
コンパイル使用メモリ 130,944 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-12 03:56:58
合計ジャッジ時間 2,110 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.array, std.container, std.range;
import std.numeric, std.math, std.bigint, std.bitmanip, std.random;
import std.string, std.conv, std.stdio, std.typecons;

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

  foreach (_; 0..t) {
    auto s = readln.chomp;
    auto r = s.length;
    foreach (i; 0..s.length - (4 + 7) + 1) {
      auto h1 = hamiltonDistance("good", s[i..i + 4]);
      foreach (j; i + 4..s.length - 7 + 1) {
        auto h2 = hamiltonDistance("problem", s[j..j + 7]);
        if (h1 + h2 < r)
          r = h1 + h2;
      }
    }

    writeln(r);
  }
}

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