結果

問題 No.345 最小チワワ問題
ユーザー kokatsu
提出日時 2022-08-27 20:33:11
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 509 bytes
コンパイル時間 2,045 ms
コンパイル使用メモリ 209,064 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-22 16:07:54
合計ジャッジ時間 3,108 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

void main() {
    string S;
    readf("%s\n", S);

    int[] C, W;
    foreach (i, s; S) {
        if (s == 'c') C ~= i.to!int;
        if (s == 'w') W ~= i.to!int;
    }

    auto WS = W.assumeSorted;

    int res = int.max;
    foreach (c; C) {
        auto ub1 = WS.upperBound(c);
        if (ub1.empty) continue;

        auto ub2 = WS.upperBound(ub1.front);
        if (ub2.empty) continue;

        res = min(res, ub2.front-c+1);
    }

    if (res == int.max) res = -1;

    res.writeln;
}
0