結果

問題 No.884 Eat and Add
ユーザー tnakao0123tnakao0123
提出日時 2019-09-14 03:17:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 1,000 ms
コード長 890 bytes
コンパイル時間 747 ms
コンパイル使用メモリ 82,316 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-18 02:09:26
合計ジャッジ時間 2,207 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 884.cc:  No.884 Eat and Add - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

/* global variables */

char s[MAX_N + 8];

/* subroutines */

/* main */

int main() {
  scanf("%s", s + 1);
  s[0] = '0';
  int n = strlen(s);
  //puts(s);

  int cnt = 0;
  for (int i = n - 1; i >= 0;) {
    while (i >= 0 && s[i] == '0') i--;
    if (i < 0) break;

    int j = i;
    while (s[j] == '1') j--;
    int l = i - j;

    if (l > 1) s[j] = '1';
    cnt++;
    i = j;
  }

  printf("%d\n", cnt);
  return 0;
}
0