結果

問題 No.884 Eat and Add
ユーザー amaridekinaiamaridekinai
提出日時 2019-09-15 22:09:39
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 9 ms / 1,000 ms
コード長 806 bytes
コンパイル時間 1,181 ms
コンパイル使用メモリ 145,740 KB
実行使用メモリ 6,700 KB
最終ジャッジ日時 2023-09-21 04:15:12
合計ジャッジ時間 1,976 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,452 KB
testcase_01 AC 3 ms
6,384 KB
testcase_02 AC 3 ms
6,368 KB
testcase_03 AC 9 ms
6,572 KB
testcase_04 AC 8 ms
6,576 KB
testcase_05 AC 9 ms
6,576 KB
testcase_06 AC 8 ms
6,700 KB
testcase_07 AC 7 ms
6,504 KB
testcase_08 AC 7 ms
6,508 KB
testcase_09 AC 7 ms
6,560 KB
testcase_10 AC 3 ms
6,372 KB
testcase_11 AC 3 ms
6,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;

void chmin(ll &a, ll b){ if( a > b){ swap(a,b);} return ;}

int main(){
string S; cin >> S; ll N = (ll) S.size();
  
  ll dp[200100][2];
  for(ll i = 0; i < 200100; i++){
    for(ll j = 0; j < 2; j++){
      dp[i][j] = INF;}}
  
  reverse(S.begin(),S.end());
  
   if( S[0] == '0'){ dp[1][0] = 0LL;}
  else{ dp[1][1] = 1LL; dp[1][0] = 1LL;}
  
  for(ll i = 1 ; i < N ; i++){
    
    if( S[i] == '0'){
     chmin(dp[i+1][0], dp[i][0]);
     chmin(dp[i+1][0], dp[i][1]+1);
     chmin(dp[i+1][1], dp[i][1]+1);}
    else{
     chmin(dp[i+1][1],dp[i][0]+1);
     chmin(dp[i+1][0],dp[i][0]+1);
     chmin(dp[i+1][1],dp[i][1]);}
  }
  
  cout << min(dp[N][0], dp[N][1]+1) << endl;
  return 0;}
0