結果

問題 No.884 Eat and Add
ユーザー tekihei2317tekihei2317
提出日時 2019-09-14 10:53:00
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 1,000 ms
コード長 741 bytes
コンパイル時間 1,758 ms
コンパイル使用メモリ 166,812 KB
実行使用メモリ 5,276 KB
最終ジャッジ日時 2023-09-19 05:35:19
合計ジャッジ時間 2,901 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 8 ms
5,056 KB
testcase_04 AC 8 ms
5,028 KB
testcase_05 AC 8 ms
4,996 KB
testcase_06 AC 8 ms
5,276 KB
testcase_07 AC 7 ms
5,036 KB
testcase_08 AC 7 ms
4,984 KB
testcase_09 AC 7 ms
5,256 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
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;}
const int INF=1e9;

int main()
{
    string s; cin>>s;
    int N=s.size();
    reverse(s.begin(),s.end());

    vector<int> dp0(N+1,INF);
    vector<int> dp1(N+1,INF);
    dp0[0]=0;

    for(int i=0;i<N;i++){
        if(s[i]=='0'){
            chmin(dp0[i+1],dp0[i]);
            chmin(dp0[i+1],dp1[i]+1);
            chmin(dp1[i+1],dp1[i]+1);
        }else{
            chmin(dp0[i+1],dp0[i]+1);
            chmin(dp1[i+1],dp0[i]+1);
            chmin(dp1[i+1],dp1[i]);
        }
    }
    cout<<min(dp0[N],dp1[N]+1)<<endl;
    return 0;
}
0