結果

問題 No.790 ちきんの括弧並べ
ユーザー tentententen
提出日時 2020-11-18 12:07:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 126 ms / 2,000 ms
コード長 870 bytes
コンパイル時間 2,028 ms
コンパイル使用メモリ 71,864 KB
実行使用メモリ 56,084 KB
最終ジャッジ日時 2023-09-30 14:54:18
合計ジャッジ時間 4,863 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,500 KB
testcase_01 AC 124 ms
55,672 KB
testcase_02 AC 126 ms
55,996 KB
testcase_03 AC 125 ms
56,016 KB
testcase_04 AC 123 ms
55,660 KB
testcase_05 AC 124 ms
53,936 KB
testcase_06 AC 123 ms
55,776 KB
testcase_07 AC 123 ms
55,720 KB
testcase_08 AC 125 ms
55,664 KB
testcase_09 AC 122 ms
55,740 KB
testcase_10 AC 123 ms
56,000 KB
testcase_11 AC 125 ms
56,084 KB
testcase_12 AC 124 ms
55,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[][] dp = new long[n + 1][n + 1];
        dp[n][n] = 1;
        for (int i = 1; i <= 2 * n; i++) {
            int right;
            int left;
            if (i > n) {
                right = 2 * n - i;
                left = 0;
            } else {
                right = n;
                left = n - i;
            }
            while (left <= right) {
                if (left < n) {
                    dp[left][right] += dp[left + 1][right];
                }
                if (right < n) {
                    dp[left][right] += dp[left][right + 1];
                }
                left++;
                right--;
            }
        }
        System.out.println(dp[0][0]);
    }
}
0