結果

問題 No.884 Eat and Add
ユーザー Imperi_NightImperi_Night
提出日時 2019-09-13 22:26:45
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 1,000 ms
コード長 1,028 bytes
コンパイル時間 735 ms
コンパイル使用メモリ 94,668 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-17 14:45:26
合計ジャッジ時間 1,376 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using ll = long long;
using P = std::pair<ll, ll>;

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug "<< i << std::endl

// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  //問題文中の添え字が0-indexか1-indexか確認!

  std::string s;
  std::cin>>s;

  ll n=s.size(),ans=0,cnt=0;

  for(ll i=n-1;i>=0;i--){
    if(s[i]=='0'){
      if(cnt>=2){
        ans++;
        cnt=1;
      }else{
        ans+=cnt;
        cnt=0;
      }
    }else{
      cnt++;
    }
  }

  if(cnt>=2)ans+=2;
  else ans+=cnt;

  std::cout<<ans;
  

  return 0;
}
0