結果

問題 No.2063 ±2^k operations (easy)
ユーザー tentententen
提出日時 2022-09-05 14:01:51
言語 Java21
(openjdk 21)
結果
AC  
実行時間 116 ms / 2,000 ms
コード長 1,903 bytes
コンパイル時間 2,863 ms
コンパイル使用メモリ 78,420 KB
実行使用メモリ 64,160 KB
最終ジャッジ日時 2024-04-30 16:59:41
合計ジャッジ時間 5,156 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
50,388 KB
testcase_01 AC 57 ms
50,516 KB
testcase_02 AC 59 ms
50,232 KB
testcase_03 AC 57 ms
50,212 KB
testcase_04 AC 57 ms
50,348 KB
testcase_05 AC 57 ms
49,928 KB
testcase_06 AC 58 ms
50,212 KB
testcase_07 AC 58 ms
50,568 KB
testcase_08 AC 58 ms
50,480 KB
testcase_09 AC 60 ms
50,128 KB
testcase_10 AC 58 ms
50,440 KB
testcase_11 AC 58 ms
50,132 KB
testcase_12 AC 58 ms
50,308 KB
testcase_13 AC 58 ms
50,304 KB
testcase_14 AC 58 ms
50,412 KB
testcase_15 AC 58 ms
50,460 KB
testcase_16 AC 58 ms
50,168 KB
testcase_17 AC 101 ms
60,656 KB
testcase_18 AC 116 ms
64,136 KB
testcase_19 AC 101 ms
60,960 KB
testcase_20 AC 100 ms
64,160 KB
testcase_21 AC 110 ms
62,240 KB
testcase_22 AC 116 ms
63,412 KB
testcase_23 AC 112 ms
62,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static char[] values;
    static int[][] dp;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        values = sc.next().toCharArray();
        int length = values.length;
        dp = new int[2][length];
        if (dfw(0, length - 1) == 2) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
    
    static int dfw(int level, int idx) {
        if (idx == 0) {
            return 1;
        }
        if (dp[level][idx] == 0) {
            if (level == 0) {
                if (values[idx] == '0') {
                    dp[level][idx] = dfw(0, idx - 1);
                } else {
                    dp[level][idx] = Math.min(dfw(1, idx - 1), dfw(0, idx - 1)) + 1;
                }
            } else {
                if (values[idx] == '1') {
                    dp[level][idx] = dfw(1, idx - 1);
                } else {
                    dp[level][idx] = Math.min(dfw(1, idx - 1), dfw(0, idx - 1)) + 1;
                }
            }
        }
        return dp[level][idx];
    }

}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    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 {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0