結果
問題 |
No.884 Eat and Add
|
ユーザー |
|
提出日時 | 2020-03-20 10:32:52 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 674 bytes |
コンパイル時間 | 1,824 ms |
コンパイル使用メモリ | 171,156 KB |
実行使用メモリ | 14,464 KB |
最終ジャッジ日時 | 2024-12-14 04:00:11 |
合計ジャッジ時間 | 2,418 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 7 WA * 2 |
ソースコード
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'); 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; }