結果

問題 No.790 ちきんの括弧並べ
ユーザー kokatsu
提出日時 2022-11-10 21:56:03
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 566 ms / 2,000 ms
コード長 393 bytes
コンパイル時間 2,018 ms
コンパイル使用メモリ 204,508 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-22 16:40:29
合計ジャッジ時間 3,479 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

void main() {
    int N;
    readf("%d\n", N);

    N *= 2;

    int res;
    foreach (i; 0 .. 1<<(N-1)) {
        bool isOK = true;
        int cnt;

        foreach (j; 0 .. N-1) {
            cnt += ((i >> j) & 1 ? -1 : 1);
            isOK &= (cnt >= 0);

            if (!isOK) break;
        }

        isOK &= (cnt == 1);

        if (isOK) ++res;
    }

    res.writeln;
}
0