結果

問題 No.790 ちきんの括弧並べ
ユーザー neko_the_shadowneko_the_shadow
提出日時 2019-02-23 16:11:28
言語 Java21
(openjdk 21)
結果
AC  
実行時間 340 ms / 2,000 ms
コード長 719 bytes
コンパイル時間 2,372 ms
コンパイル使用メモリ 74,528 KB
実行使用メモリ 44,752 KB
最終ジャッジ日時 2024-05-07 13:51:56
合計ジャッジ時間 4,649 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
41,164 KB
testcase_01 AC 118 ms
41,332 KB
testcase_02 AC 111 ms
41,120 KB
testcase_03 AC 115 ms
41,372 KB
testcase_04 AC 117 ms
41,048 KB
testcase_05 AC 128 ms
44,752 KB
testcase_06 AC 126 ms
41,112 KB
testcase_07 AC 119 ms
41,500 KB
testcase_08 AC 182 ms
41,416 KB
testcase_09 AC 340 ms
41,712 KB
testcase_10 AC 117 ms
41,500 KB
testcase_11 AC 114 ms
41,384 KB
testcase_12 AC 130 ms
41,428 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