結果

問題 No.150 "良問"(良問とは言っていない
ユーザー te-shte-sh
提出日時 2016-08-31 00:54:32
言語 D
(dmd 2.105.2)
結果
AC  
実行時間 92 ms / 5,000 ms
コード長 686 bytes
コンパイル時間 1,288 ms
コンパイル使用メモリ 152,012 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-09-02 21:41:46
合計ジャッジ時間 2,844 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
4,368 KB
testcase_01 AC 1 ms
4,368 KB
testcase_02 AC 1 ms
4,368 KB
testcase_03 AC 1 ms
4,368 KB
testcase_04 AC 1 ms
4,368 KB
testcase_05 AC 2 ms
4,372 KB
testcase_06 AC 92 ms
4,368 KB
testcase_07 AC 1 ms
4,368 KB
testcase_08 AC 2 ms
4,372 KB
testcase_09 AC 1 ms
4,368 KB
testcase_10 AC 22 ms
4,372 KB
testcase_11 AC 24 ms
4,368 KB
testcase_12 AC 17 ms
4,368 KB
testcase_13 AC 23 ms
4,372 KB
testcase_14 AC 30 ms
4,372 KB
testcase_15 AC 28 ms
4,372 KB
testcase_16 AC 3 ms
4,372 KB
testcase_17 AC 9 ms
4,372 KB
testcase_18 AC 26 ms
4,368 KB
testcase_19 AC 33 ms
4,372 KB
testcase_20 AC 34 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

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