結果

問題 No.790 ちきんの括弧並べ
ユーザー htensaihtensai
提出日時 2020-02-05 09:18:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 140 ms / 2,000 ms
コード長 659 bytes
コンパイル時間 3,226 ms
コンパイル使用メモリ 74,124 KB
実行使用メモリ 57,532 KB
最終ジャッジ日時 2023-10-22 02:29:49
合計ジャッジ時間 6,394 ms
ジャッジサーバーID
(参考情報)
judge13 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 140 ms
57,276 KB
testcase_01 AC 138 ms
57,268 KB
testcase_02 AC 137 ms
57,300 KB
testcase_03 AC 137 ms
57,464 KB
testcase_04 AC 140 ms
57,532 KB
testcase_05 AC 138 ms
57,340 KB
testcase_06 AC 138 ms
57,308 KB
testcase_07 AC 136 ms
57,512 KB
testcase_08 AC 137 ms
57,364 KB
testcase_09 AC 137 ms
57,168 KB
testcase_10 AC 137 ms
57,408 KB
testcase_11 AC 136 ms
57,264 KB
testcase_12 AC 138 ms
57,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static long[][] dp;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        dp = new long[n + 1][n + 1];
        dp[0][0] = 1;
        System.out.println(dfw(n , n));
    }
    
    static long dfw(int open, int close) {
        if (open < 0 || close < 0) {
            return 0;
        }
        if (open < close) {
            return 0;
        }
        if (dp[open][close] != 0) {
            return dp[open][close];
        }
        dp[open][close] = dfw(open - 1, close) + dfw(open, close - 1);
        return dp[open][close];
    }
}
0