結果

問題 No.884 Eat and Add
ユーザー snow39snow39
提出日時 2019-09-13 22:07:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 1,000 ms
コード長 863 bytes
コンパイル時間 754 ms
コンパイル使用メモリ 91,564 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-17 14:24:26
合計ジャッジ時間 1,408 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int N;
string S;

int main(){
  cin>>S;
  N=S.size();

  string T=S;
  reverse(T.begin(),T.end());

  int ans=0;
  int one=0;
  for(int i=0;i<N;i++){
      if(T[i]=='1') one++;
      else one=0;

      if(i+1<N){
          if(T[i]=='1'&&T[i+1]=='0'){
              ans++;
              if(one>1){
                  T[i+1]='1';
              }
              one=0;
          }
      }else{
          if(T[i]=='1'){
              if(one>1) ans+=2;
              else ans++;
          }
      }
  }

  cout<<ans<<endl;

  return 0;
}
0