結果
問題 |
No.884 Eat and Add
|
ユーザー |
![]() |
提出日時 | 2019-09-14 19:11:12 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 6 ms / 1,000 ms |
コード長 | 584 bytes |
コンパイル時間 | 1,618 ms |
コンパイル使用メモリ | 166,276 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-06 10:42:30 |
合計ジャッジ時間 | 2,286 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 9 |
ソースコード
#include "bits/stdc++.h" using namespace std; void solve() { string s; cin >> s; int n = s.size(); int dp[] = {0, 10000000}; for (int i = n - 1; i >= 0; i--) { int nx[2] = {}; if (s[i] == '0') { nx[0] = min(dp[0], dp[1] + 1); nx[1] = min(dp[1] + 1, dp[0] + 2); } else { nx[0] = dp[0] + 1; nx[1] = min(dp[1], dp[0] + 1); } swap(dp, nx); } cout << min(dp[0], dp[1] + 1) << endl; } int main() { solve(); return 0; }