結果
問題 | No.884 Eat and Add |
ユーザー |
|
提出日時 | 2020-03-20 11:01:59 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 23 ms / 1,000 ms |
コード長 | 728 bytes |
コンパイル時間 | 1,720 ms |
コンパイル使用メモリ | 172,632 KB |
実行使用メモリ | 14,524 KB |
最終ジャッジ日時 | 2024-12-14 04:00:59 |
合計ジャッジ時間 | 2,504 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 9 |
ソースコード
typedef long long ll; #include <bits/stdc++.h> using namespace std; int main() { string s; std::cin >> s; ll n = s.length(); // i桁目までみたときのコスト、jは繰り上がっているかフラグ vector<vector<ll>> dp(n+1,vector<ll>(2,0)); dp[0][0]=dp[0][1]=(s[n-1]=='1'); if(s[n-1]=='0'){ dp[0][1]=1e10; } for (int i = 1; i < n; i++) { ll now = n-i-1; if(s[now]=='1'){ dp[i][1] = min(dp[i-1][0]+1,dp[i-1][1]); dp[i][0] = dp[i-1][0]+1; }else{ dp[i][1] = dp[i-1][1]+1; dp[i][0] = min(dp[i-1][0],dp[i-1][1]+1); } } std::cout << min(dp[n-1][1]+1,dp[n-1][0]) << std::endl; }