結果

問題 No.884 Eat and Add
ユーザー tentententen
提出日時 2021-11-19 11:48:57
言語 Java21
(openjdk 21)
結果
AC  
実行時間 108 ms / 1,000 ms
コード長 1,444 bytes
コンパイル時間 4,151 ms
コンパイル使用メモリ 74,372 KB
実行使用メモリ 52,528 KB
最終ジャッジ日時 2023-08-28 21:01:15
合計ジャッジ時間 5,675 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,168 KB
testcase_01 AC 41 ms
49,228 KB
testcase_02 AC 40 ms
49,504 KB
testcase_03 AC 107 ms
52,324 KB
testcase_04 AC 108 ms
52,344 KB
testcase_05 AC 108 ms
52,416 KB
testcase_06 AC 104 ms
52,396 KB
testcase_07 AC 104 ms
52,528 KB
testcase_08 AC 105 ms
52,296 KB
testcase_09 AC 101 ms
52,460 KB
testcase_10 AC 41 ms
49,360 KB
testcase_11 AC 41 ms
49,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        char[] values = sc.next().toCharArray();
        int plus = 2;
        int normal = 0;
        for (int i = values.length - 1; i >= 0; i--) {
            int nextPlus;
            int nextNormal;
            if (values[i] == '1') {
                nextPlus = Math.min(plus, normal + 1);
                nextNormal = normal + 1;
            } else {
                nextPlus = plus + 1;
                nextNormal = Math.min(plus + 1, normal);
            }
            plus = nextPlus;
            normal = nextNormal;
        }
        System.out.println(Math.min(plus + 1, normal));
    }
}

class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0