結果

問題 No.884 Eat and Add
ユーザー beetbeet
提出日時 2019-09-13 21:38:28
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 10 ms / 1,000 ms
コード長 652 bytes
コンパイル時間 1,954 ms
コンパイル使用メモリ 201,120 KB
実行使用メモリ 6,668 KB
最終ジャッジ日時 2023-09-17 07:01:16
合計ジャッジ時間 2,762 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 10 ms
6,644 KB
testcase_04 AC 10 ms
6,668 KB
testcase_05 AC 10 ms
6,644 KB
testcase_06 AC 10 ms
6,576 KB
testcase_07 AC 8 ms
6,580 KB
testcase_08 AC 9 ms
6,576 KB
testcase_09 AC 8 ms
6,640 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0