結果

問題 No.884 Eat and Add
ユーザー tekihei2317tekihei2317
提出日時 2019-09-14 11:02:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 1,000 ms
コード長 789 bytes
コンパイル時間 1,666 ms
コンパイル使用メモリ 166,060 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-19 05:46:45
合計ジャッジ時間 2,666 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 12 ms
4,380 KB
testcase_04 AC 11 ms
4,380 KB
testcase_05 AC 11 ms
4,380 KB
testcase_06 AC 11 ms
4,388 KB
testcase_07 AC 10 ms
4,380 KB
testcase_08 AC 10 ms
4,380 KB
testcase_09 AC 11 ms
4,380 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 2 ms
4,380 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> dp(2,INF);
    dp[0]=0;
    for(int i=0;i<N;i++){
        vector<int> ndp(2,INF);
        int d=s[i]-'0';
        for(int j=0;j<2;j++){
            if(d+j==0){
                chmin(ndp[0],dp[j]);
            }else if(d+j==1){
                chmin(ndp[0],dp[j]+1);
                chmin(ndp[1],dp[j]+1);
            }else{
                chmin(ndp[1],dp[j]);
            }
        }
        swap(dp,ndp);
    }
    cout<<min(dp[0],dp[1]+1)<<endl;
    return 0;
}
0