結果

問題 No.910 素数部分列
ユーザー nebukuro09
提出日時 2019-10-18 21:49:21
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 12 ms / 1,000 ms
コード長 786 bytes
コンパイル時間 733 ms
コンパイル使用メモリ 114,852 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-22 02:47:50
合計ジャッジ時間 2,441 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

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 N = readln.chomp.to!int;
    auto S = readln.chomp;
    auto T = S.filter!(s => s == '1' || s == '9').array;

    int ans = S.length.to!int - T.length.to!int;

    int ichi = 0;
    int kyuu = 0;

    foreach_reverse (i; 0..T.length.to!int) {
        if (T[i] == '1') {
            if (kyuu > 0) {
                ans += 1;
                kyuu -= 1;
            } else {
                ichi += 1;
            }
        } else {
            kyuu += 1;
        }
    }

    int x = min(kyuu / 2, ichi);
    ans += x;

    ans += (ichi - x) / 2;

    ans.writeln;
}
0