結果
| 問題 |
No.884 Eat and Add
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-09-14 23:59:24 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 27 ms / 1,000 ms |
| コード長 | 729 bytes |
| コンパイル時間 | 786 ms |
| コンパイル使用メモリ | 109,684 KB |
| 実行使用メモリ | 10,288 KB |
| 最終ジャッジ日時 | 2024-06-22 02:34:32 |
| 合計ジャッジ時間 | 1,591 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 9 |
ソースコード
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;
}