結果
| 問題 |
No.2063 ±2^k operations (easy)
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2022-09-05 14:01:51 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 113 ms / 2,000 ms |
| コード長 | 1,903 bytes |
| コンパイル時間 | 2,681 ms |
| コンパイル使用メモリ | 78,428 KB |
| 実行使用メモリ | 64,244 KB |
| 最終ジャッジ日時 | 2024-11-20 13:54:46 |
| 合計ジャッジ時間 | 5,404 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
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();
}
}
tenten