結果
問題 | No.884 Eat and Add |
ユーザー |
|
提出日時 | 2020-04-17 11:23:18 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 19 ms / 1,000 ms |
コード長 | 819 bytes |
コンパイル時間 | 1,419 ms |
コンパイル使用メモリ | 171,156 KB |
実行使用メモリ | 14,472 KB |
最終ジャッジ日時 | 2024-10-03 10:10:36 |
合計ジャッジ時間 | 2,401 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 9 |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<n;i++) using namespace std; using ll = long long ; using P = pair<int,int> ; const int INF = 1e9; const int MOD = 1000000007; int main(){ string s; cin >> s; int n = s.size(); vector<vector<int>> dp(n+1,vector<int>(2,INF)); dp[0][0] = 0; for(int i=1;i<=n;i++){ int sd = s[n-i] - '0'; //cout << sd << endl; if(sd == 0){ dp[i][0] = min(dp[i-1][0],dp[i-1][1] + 1); dp[i][1] = dp[i-1][1] + 1; }else{ dp[i][0] = dp[i-1][0] + 1; dp[i][1] = min(dp[i-1][0] + 1,dp[i-1][1]); } } dp[n][1] ++; cout << min(dp[n][0],dp[n][1]) << endl; /* rep(i,n){ rep(j,2) cout << dp[i][j] << " "; cout << endl; }*/ return 0; }