結果

問題 No.884 Eat and Add
ユーザー nebukuro09nebukuro09
提出日時 2019-09-14 23:59:24
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 25 ms / 1,000 ms
コード長 729 bytes
コンパイル時間 633 ms
コンパイル使用メモリ 96,100 KB
実行使用メモリ 10,808 KB
最終ジャッジ日時 2023-09-04 02:46:52
合計ジャッジ時間 1,402 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 25 ms
9,824 KB
testcase_04 AC 25 ms
9,856 KB
testcase_05 AC 25 ms
10,540 KB
testcase_06 AC 24 ms
10,400 KB
testcase_07 AC 24 ms
10,056 KB
testcase_08 AC 24 ms
10,808 KB
testcase_09 AC 24 ms
9,936 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 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.stdio;

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

    auto dp = new int[][](N+1, 2);
    foreach (i; 0..N+1) dp[i][] = 1 << 29;
    dp[0][0] = 0;

    foreach (i; 0..N) {
        if (S[i] == '0') {
            dp[i+1][0] = min(dp[i+1][0], dp[i][0], dp[i][1] + 3);
            dp[i+1][1] = min(dp[i+1][1], dp[i][1] + 1);
        } else {
            dp[i+1][0] = min(dp[i+1][0], dp[i][0] + 1, dp[i][1] + 2);
            dp[i+1][1] = min(dp[i+1][1], dp[i][0], dp[i][1]);
        }
    }

    dp[N][0].writeln;
}
0