結果
| 問題 |
No.884 Eat and Add
|
| コンテスト | |
| ユーザー |
beet
|
| 提出日時 | 2019-09-13 21:38:28 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 10 ms / 1,000 ms |
| コード長 | 652 bytes |
| コンパイル時間 | 1,844 ms |
| コンパイル使用メモリ | 196,036 KB |
| 最終ジャッジ日時 | 2025-01-07 17:46:49 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 9 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
//INSERT ABOVE HERE
signed main(){
string s;
cin>>s;
Int n=s.size();
reverse(s.begin(),s.end());
const Int INF = 1e9;
vector<Int> dp0(n+1,INF),dp1(n+1,INF);
dp0[0]=0;
for(Int i=0;i<n;i++){
chmin(dp0[i+1],dp0[i]+(s[i]!='0'));
chmin(dp0[i+1],dp1[i]+1+(s[i]!='0'));
chmin(dp1[i+1],dp0[i]+1+(s[i]=='0'));
chmin(dp1[i+1],dp1[i]+(s[i]=='0'));
}
cout<<min(dp0[n],dp1[n]+1)<<endl;
return 0;
}
beet