結果

問題 No.790 ちきんの括弧並べ
ユーザー neko_the_shadowneko_the_shadow
提出日時 2019-02-23 16:11:28
言語 Java21
(openjdk 21)
結果
AC  
実行時間 381 ms / 2,000 ms
コード長 719 bytes
コンパイル時間 4,117 ms
コンパイル使用メモリ 70,940 KB
実行使用メモリ 56,440 KB
最終ジャッジ日時 2023-08-20 06:31:02
合計ジャッジ時間 7,268 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
55,512 KB
testcase_01 AC 119 ms
56,060 KB
testcase_02 AC 119 ms
55,932 KB
testcase_03 AC 122 ms
55,808 KB
testcase_04 AC 123 ms
55,756 KB
testcase_05 AC 129 ms
55,824 KB
testcase_06 AC 129 ms
55,832 KB
testcase_07 AC 134 ms
55,644 KB
testcase_08 AC 191 ms
56,048 KB
testcase_09 AC 381 ms
56,440 KB
testcase_10 AC 121 ms
55,836 KB
testcase_11 AC 123 ms
56,028 KB
testcase_12 AC 144 ms
55,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);
        int n = stdin.nextInt();
        int ans = 0;
        loop: for (int bit = 0; bit < (1 << (2 * n)); bit++) {
            if (Integer.bitCount(bit) != n) continue;
            
            int x = 0;
            int y = 0;
            for (int i = 0; i < 2 * n; i++) {
                if ((bit & (1 << i)) == 0) {
                    x++;
                } else {
                    y++;
                }
                
                if (y < x) continue loop;
            }
            
            ans++;
        }
        
        System.out.println(ans);
    }
}
0