結果

問題 No.884 Eat and Add
ユーザー htensaihtensai
提出日時 2020-01-28 12:26:13
言語 Java21
(openjdk 21)
結果
AC  
実行時間 91 ms / 1,000 ms
コード長 731 bytes
コンパイル時間 2,008 ms
コンパイル使用メモリ 72,052 KB
実行使用メモリ 52,380 KB
最終ジャッジ日時 2023-10-13 15:12:12
合計ジャッジ時間 4,359 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,276 KB
testcase_01 AC 44 ms
49,160 KB
testcase_02 AC 43 ms
49,596 KB
testcase_03 AC 91 ms
51,808 KB
testcase_04 AC 91 ms
51,824 KB
testcase_05 AC 91 ms
52,088 KB
testcase_06 AC 90 ms
52,036 KB
testcase_07 AC 88 ms
52,380 KB
testcase_08 AC 88 ms
52,332 KB
testcase_09 AC 89 ms
52,320 KB
testcase_10 AC 42 ms
49,068 KB
testcase_11 AC 42 ms
49,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        char[] arr = br.readLine().toCharArray();
        boolean isUp = false;
        int count = 0;
        for (int i = arr.length - 1; i >= 0; i--) {
            boolean now = arr[i] == '1';
            if (isUp ^ now) {
                count++;
                if (i != 0 && arr[i - 1] == '1') {
                    isUp = true;
                } else {
                    isUp = false;
                }
            }
        }
        if (isUp) {
            count++;
        }
        System.out.println(count);
   }
}
0