結果

問題 No.411 昇順昇順ソート
ユーザー htensaihtensai
提出日時 2020-02-05 10:15:01
言語 Java21
(openjdk 21)
結果
AC  
実行時間 134 ms / 2,000 ms
コード長 976 bytes
コンパイル時間 3,697 ms
コンパイル使用メモリ 83,956 KB
実行使用メモリ 57,684 KB
最終ジャッジ日時 2023-10-22 03:49:54
合計ジャッジ時間 8,664 ms
ジャッジサーバーID
(参考情報)
judge10 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
57,524 KB
testcase_01 AC 131 ms
57,552 KB
testcase_02 AC 130 ms
57,528 KB
testcase_03 AC 131 ms
57,388 KB
testcase_04 AC 132 ms
57,524 KB
testcase_05 AC 131 ms
57,308 KB
testcase_06 AC 131 ms
57,548 KB
testcase_07 AC 133 ms
57,488 KB
testcase_08 AC 130 ms
57,020 KB
testcase_09 AC 132 ms
57,432 KB
testcase_10 AC 133 ms
57,400 KB
testcase_11 AC 132 ms
57,516 KB
testcase_12 AC 132 ms
57,508 KB
testcase_13 AC 132 ms
57,324 KB
testcase_14 AC 131 ms
57,468 KB
testcase_15 AC 131 ms
57,556 KB
testcase_16 AC 132 ms
57,468 KB
testcase_17 AC 132 ms
57,424 KB
testcase_18 AC 132 ms
57,408 KB
testcase_19 AC 131 ms
57,412 KB
testcase_20 AC 132 ms
57,544 KB
testcase_21 AC 132 ms
57,440 KB
testcase_22 AC 131 ms
57,464 KB
testcase_23 AC 131 ms
57,588 KB
testcase_24 AC 131 ms
57,396 KB
testcase_25 AC 131 ms
57,440 KB
testcase_26 AC 133 ms
57,368 KB
testcase_27 AC 134 ms
57,440 KB
testcase_28 AC 131 ms
57,120 KB
testcase_29 AC 131 ms
55,780 KB
testcase_30 AC 131 ms
57,464 KB
testcase_31 AC 131 ms
57,684 KB
testcase_32 AC 131 ms
57,564 KB
testcase_33 AC 132 ms
57,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        if (n == 2 && k == 1) {
            System.out.println(0);
            return;
        }
        long[][] comb = new long[n + 1][n + 1];
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= i; j++) {
                if (j == 0 || j == i) {
                    comb[i][j] = 1;
                } else {
                    comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
                }
            }
        }
        long total = 1;
        if (k == 1) {
            for (int i = 1; i < n - 2 && i <= n - k; i++) {
                total += comb[n - k][i];
            }
        } else {
            for (int i = 1; i < n - 1 && i <= n - k; i++) {
                total += comb[n - k][i];
            }
        }
        System.out.println(total);
    }
}
0