結果
問題 |
No.884 Eat and Add
|
ユーザー |
![]() |
提出日時 | 2019-09-13 22:43:21 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 20 ms / 1,000 ms |
コード長 | 833 bytes |
コンパイル時間 | 702 ms |
コンパイル使用メモリ | 85,860 KB |
実行使用メモリ | 14,208 KB |
最終ジャッジ日時 | 2024-07-04 10:06:56 |
合計ジャッジ時間 | 1,466 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 9 |
ソースコード
#include <iostream> #include <vector> #include <map> #include <set> #include <queue> #include <string> #include <iomanip> #include <algorithm> #include <cmath> #include <stdio.h> using namespace std; #define int long long int MOD = 1000000007; void amin(int &a, const int &b) { a = min(a, b); } signed main() { cin.tie(0); ios::sync_with_stdio(false); string S; cin >> S; int N = S.size(); int INF = (int)1 << 60; vector<vector<int> > dp(N + 1, vector<int>(2, INF)); dp[0][0] = 0; for (int i = 0; i < N; i++) { if (S[N - i - 1] == '0') { amin(dp[i + 1][0], dp[i][0]); amin(dp[i + 1][1], dp[i][1] + 1); amin(dp[i + 1][0], dp[i][1] + 1); } else { amin(dp[i + 1][1], dp[i][0] + 1); amin(dp[i + 1][0], dp[i][0] + 1); amin(dp[i + 1][1], dp[i][1]); } } cout << min(dp[N][0], dp[N][1] + 1) << endl; }