結果

問題 No.145 yukiover
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-12-27 18:22:13
言語 D
(dmd 2.105.2)
結果
WA  
実行時間 -
コード長 1,182 bytes
コンパイル時間 2,477 ms
コンパイル使用メモリ 148,416 KB
実行使用メモリ 4,924 KB
最終ジャッジ日時 2023-09-03 00:15:34
合計ジャッジ時間 2,467 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,380 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 WA -
testcase_11 AC 3 ms
4,500 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
void log(A...)(A arg) { stderr.writeln(arg); }
int size(T)(in T s) { return cast(int)s.length; }

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

    auto r = 0;
    auto ans = s.count!"a == 'z'";
    auto prev = s.count!"a == 'y'";
    foreach (p ; zip("yuk", "uki")) {
        //log("p: ", p);
        int nprev = 0;
        foreach (c ; s) {
            if (p[1] < c && c < p[0]) {
                if (prev > 0) {
                    prev--;
                    ans++;
                }
            } else if (p[1] == c) {
                nprev++;
            }
        }
        assert(prev >= 0 && nprev >= 0 && r >= 0);
        if (p[0] == 'y') {
            auto d = max(0, prev - nprev) / 2;
            ans += d;
            r += max(0, prev - nprev - 2 * d);
        } else {
            r += abs(prev - nprev);
        }
        ans += min(prev, r);
        prev -= min(prev, r);
        prev = min(prev, nprev);
    }
    writeln(ans);
}
0