結果

問題 No.287 場合の数
ユーザー htensaihtensai
提出日時 2020-01-24 20:45:17
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,412 bytes
コンパイル時間 1,856 ms
コンパイル使用メモリ 74,160 KB
実行使用メモリ 56,412 KB
最終ジャッジ日時 2023-10-12 04:19:17
合計ジャッジ時間 16,122 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3,281 ms
56,412 KB
testcase_01 AC 115 ms
55,580 KB
testcase_02 AC 117 ms
55,888 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static long total = 0;
    static long max;
    static int[] kaijox = new int[9];
    static int n;
    public static void main(String[]  args) {
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i <= 8; i++) {
            kaijox[i] = kaijo(i);
        }
        n = sc.nextInt();
        max = 6 * n;
        int[] arr = new int[8];
        calc(0, 0, 0, arr);
        System.out.println(total);
    }
    
    static void calc(int idx, int sum, int used, int[] arr) {
        if (idx >= 8) {
            count(arr);
            return;
        }
        for (int i = used; i * (8 - idx) + sum <= max; i++) {
            if (sum + i + n * (8 - idx - 1) < max) {
                continue;
            }
            arr[idx] = i;
            calc(idx + 1, sum + i, i, arr);
        }
    }
    
    static void count(int[] arr) {
        int prev = arr[0];
        int cnt = 1;
        int ans = kaijox[8];
        for (int i = 1; i < 8; i++) {
            if (arr[i] == prev) {
                cnt++;
            } else {
                ans /= kaijox[cnt];
                cnt = 1;
                prev = arr[i];
            }
        }
        ans /= kaijox[cnt];
        total += ans;
    }
    
    static int kaijo(int x) {
        if (x < 2) {
            return 1;
        } else {
            return x * kaijo(x - 1);
        }
    }
    
}
0