結果

問題 No.884 Eat and Add
ユーザー tempura_pptempura_pp
提出日時 2019-09-13 22:04:18
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 1,000 ms
コード長 920 bytes
コンパイル時間 780 ms
コンパイル使用メモリ 94,892 KB
実行使用メモリ 5,240 KB
最終ジャッジ日時 2023-09-17 14:23:03
合計ジャッジ時間 1,494 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 8 ms
5,144 KB
testcase_04 AC 7 ms
5,044 KB
testcase_05 AC 8 ms
5,100 KB
testcase_06 AC 7 ms
5,240 KB
testcase_07 AC 6 ms
5,100 KB
testcase_08 AC 6 ms
5,092 KB
testcase_09 AC 7 ms
5,160 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int dp[202020][2];
int main(){
    string s;
    cin>>s;
    reverse(s.begin(),s.end());
    s+='0';
    s+='0';
    int n = s.size();
    dp[0][1]=inf;
    rep(i,n){
        if(s[i]=='1'){
            dp[i+1][1]=min(dp[i][1],dp[i][0]+1);
            dp[i+1][0]=dp[i][0]+1;
        }
        else {
            dp[i+1][1]=dp[i][1]+1;
            dp[i+1][0]=min(dp[i][1]+1,dp[i][0]);
        }
    }
    cout<<dp[n][0]<<endl;
    return 0;
}
0