結果

問題 No.145 yukiover
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-12-27 18:47:28
言語 D
(dmd 2.107.1)
結果
WA  
実行時間 -
コード長 1,316 bytes
コンパイル時間 1,267 ms
コンパイル使用メモリ 148,020 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-09-03 00:16:01
合計ジャッジ時間 2,385 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 WA -
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 WA -
testcase_11 AC 3 ms
4,376 KB
testcase_12 WA -
testcase_13 AC 5 ms
4,380 KB
testcase_14 AC 5 ms
4,376 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 3 ms
4,380 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;

    int r = 0;
    int ans = cast(int)s.count!"a == 'z'";
    int prev = cast(int)s.count!"a == 'y'";
    int i = 0;
    foreach (p ; zip("yuk", "uki")) {
        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 (prev > nprev) {
            auto d = (prev - nprev) / 2;
            ans += d;
            r += max(0, (i + 1) * (prev - nprev - 2 * d));
            prev = nprev;
        } else {
            auto d = nprev - prev;
            r += d;
            auto e = min(prev, r);
            ans += e;
            prev -= e;
            r -= e;
        }
        //log([prev, nprev, r, ans]);
        i++;
    }
    ans += r / 2;
    writeln(ans);
}
0