結果

問題 No.884 Eat and Add
ユーザー tenten
提出日時 2021-11-19 11:48:57
言語 Java
(openjdk 23)
結果
AC  
実行時間 125 ms / 1,000 ms
コード長 1,444 bytes
コンパイル時間 2,441 ms
コンパイル使用メモリ 77,396 KB
実行使用メモリ 39,840 KB
最終ジャッジ日時 2024-12-30 09:02:09
合計ジャッジ時間 4,655 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 9
権限があれば一括ダウンロードができます

ソースコード

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