結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 4 ms
6,444 KB
testcase_02 AC 3 ms
6,476 KB
testcase_03 AC 8 ms
6,604 KB
testcase_04 AC 9 ms
6,828 KB
testcase_05 AC 8 ms
6,584 KB
testcase_06 AC 8 ms
6,560 KB
testcase_07 AC 8 ms
6,496 KB
testcase_08 AC 7 ms
6,704 KB
testcase_09 AC 7 ms
6,588 KB
testcase_10 AC 3 ms
6,700 KB
testcase_11 WA -
権限があれば一括ダウンロードができます

ソースコード

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] = 0LL;}
  
  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