結果

問題 No.2518 Adjacent Larger
ユーザー InTheBloomInTheBloom
提出日時 2023-10-27 22:54:02
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 1,349 bytes
コンパイル時間 3,137 ms
コンパイル使用メモリ 168,108 KB
実行使用メモリ 6,996 KB
最終ジャッジ日時 2023-10-27 22:54:08
合計ジャッジ時間 2,686 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 21 ms
4,348 KB
testcase_02 AC 22 ms
4,348 KB
testcase_03 AC 20 ms
4,348 KB
testcase_04 AC 20 ms
4,348 KB
testcase_05 AC 20 ms
4,348 KB
testcase_06 AC 7 ms
4,348 KB
testcase_07 AC 8 ms
4,348 KB
testcase_08 AC 8 ms
4,348 KB
testcase_09 AC 8 ms
4,348 KB
testcase_10 AC 7 ms
4,348 KB
testcase_11 AC 6 ms
5,252 KB
testcase_12 AC 6 ms
5,252 KB
testcase_13 AC 6 ms
5,252 KB
testcase_14 AC 6 ms
5,252 KB
testcase_15 AC 6 ms
5,252 KB
testcase_16 AC 23 ms
6,932 KB
testcase_17 AC 12 ms
5,500 KB
testcase_18 AC 13 ms
5,500 KB
testcase_19 AC 11 ms
4,976 KB
testcase_20 AC 16 ms
5,836 KB
testcase_21 AC 17 ms
6,996 KB
testcase_22 AC 16 ms
6,996 KB
testcase_23 AC 23 ms
6,996 KB
testcase_24 AC 18 ms
6,840 KB
testcase_25 AC 19 ms
6,996 KB
testcase_26 AC 19 ms
6,996 KB
testcase_27 AC 16 ms
6,996 KB
testcase_28 AC 20 ms
6,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

void main () {
    int T = readln.chomp.to!int;

    foreach (_; 0..T) {
        int N = readln.split[0].to!int;
        int[] A = readln.split.to!(int[]);

        auto ans = solve(N, A);
        writeln(ans);
    }
}

auto solve (int N, int[] A) {
    /**
     * 必要条件
     * - 0と2が少なくとも1つ
     * - 0と2は同じものが連続することがない
     * - 0と2は同じ数だけ存在
     * かなー未証明だけど提出チャレンジする
     * 
     * WAした。まだなんか抜けてるみたい
     */

    int zero = 0, two = 0;
    foreach (a; A) {
        if (a == 0) zero++;
        if (a == 2) two++;
    }

    if (zero != two || zero == 0 || two == 0) return "No";

    foreach (i; 0..A.length) {
        if (A[i] == 0 || A[i] == 2) {
            if (A[i] == A[(i+1)%A.length]) return "No";
        }
    }

    bool isNextZero = false;
    bool first = true;
    foreach (a; chain(A, A)) {
        if (first && a == 0) { isNextZero = false; first = false; continue; }
        if (first && a == 2) { isNextZero = true; first = false; continue; }

        if (first) continue;

        if (a == 0 && isNextZero) { isNextZero = false; continue; }
        if (a == 2 && !isNextZero) { isNextZero = true; continue; }

        if (a == 0 || a == 2) return "No";
    }

    return "Yes";
}
0