結果

問題 No.2283 Prohibit Three Consecutive
ユーザー ks2mks2m
提出日時 2023-04-28 22:11:42
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,435 bytes
コンパイル時間 1,929 ms
コンパイル使用メモリ 73,788 KB
実行使用メモリ 61,296 KB
最終ジャッジ日時 2023-08-11 07:05:22
合計ジャッジ時間 5,854 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
55,652 KB
testcase_01 AC 120 ms
56,032 KB
testcase_02 AC 123 ms
55,936 KB
testcase_03 AC 211 ms
58,952 KB
testcase_04 AC 209 ms
58,856 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 200 ms
59,024 KB
testcase_09 AC 195 ms
58,532 KB
testcase_10 AC 196 ms
58,320 KB
testcase_11 AC 200 ms
58,408 KB
testcase_12 WA -
testcase_13 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		PrintWriter pw = new PrintWriter(System.out);
		for (int z = 0; z < t; z++) {
			int n = sc.nextInt();
			char[] s = sc.next().toCharArray();

			int m = n + 5;
			boolean[] dp00 = new boolean[m];
			boolean[] dp01 = new boolean[m];
			boolean[] dp10 = new boolean[m];
			boolean[] dp11 = new boolean[m];
			if (s[0] != '1') {
				dp00[0] = true;
				dp10[0] = true;
			}
			if (s[0] != '0') {
				dp01[0] = true;
				dp11[0] = true;
			}

			if (s[1] != '1') {
				if (dp00[0] || dp10[0]) {
					dp00[1] = true;
				}
				if (dp01[0] || dp11[0]) {
					dp10[1] = true;
				}
			}
			if (s[1] != '0') {
				if (dp00[0] || dp10[0]) {
					dp01[1] = true;
				}
				if (dp01[0] || dp11[0]) {
					dp11[1] = true;
				}
			}

			for (int i = 2; i < m; i++) {
				if (s[i % n] != '1') {
					if (dp10[i - 1]) {
						dp00[i] = true;
					}
					if (dp01[i - 1] || dp11[i - 1]) {
						dp10[i] = true;
					}
				}
				if (s[i % n] != '0') {
					if (dp00[i - 1] || dp10[i - 1]) {
						dp01[i] = true;
					}
					if (dp01[i - 1]) {
						dp11[i] = true;
					}
				}
			}

			if (dp00[n + 1] || dp01[n + 1] || dp10[n + 1] || dp11[n + 1]) {
				pw.println("Yes");
			} else {
				pw.println("No");
			}
		}
		pw.flush();
		sc.close();
	}
}
0