結果

問題 No.252 "良問"(良問とは言っていない (2)
ユーザー nebukuro09nebukuro09
提出日時 2017-04-05 01:21:26
言語 D
(dmd 2.105.2)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 1,352 bytes
コンパイル時間 865 ms
コンパイル使用メモリ 101,096 KB
実行使用メモリ 13,036 KB
最終ジャッジ日時 2023-09-03 12:41:21
合計ジャッジ時間 1,961 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
7,192 KB
testcase_01 AC 59 ms
4,380 KB
testcase_02 AC 50 ms
9,996 KB
testcase_03 AC 50 ms
13,004 KB
testcase_04 AC 50 ms
13,036 KB
testcase_05 AC 50 ms
12,712 KB
testcase_06 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


void main() {
    auto T = readln.chomp.to!int;
    const auto G = "good";
    const auto P = "problem";

    foreach (t; 0..T) {
        auto S = readln.chomp;
        auto N = S.length.to!int;

        auto cnt = new int[](N);
        fill(cnt, 1 << 30);

        foreach (i; 4..N-6) {
            cnt[i] = 0;
            foreach (j; 0..7) {
                if (S[i+j] != P[j]) cnt[i] += 1;
            }
        }
        foreach (i; iota(N-2, -1, -1)) cnt[i] = min(cnt[i], cnt[i+1]);
        //cnt.writeln;

        auto cnt_problem = new int[](N);
        foreach (i; 0..N-6) {
            if (S[i..i+7] == P) cnt_problem[i] = 1;
        }
        foreach (i; 0..N-1) cnt_problem[i+1] += cnt_problem[i];


        int ans = 1 << 30;
        foreach (i; 0..N-10) {
            int cnt_g = 0;
            foreach (j; 0..4) {
                if (S[i+j] != G[j]) cnt_g += 1;
            }

            if (i < 7)
                ans = min(ans, cnt_g + cnt[i+4]);
            else
                ans = min(ans, cnt_g + cnt[i+4] + cnt_problem[i-7]);
            //writeln(i, " ", cnt[i+4], " ", cnt_g, " ", ans);
        }

        ans.writeln;
    }
}
0