結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3,535 ms
56,128 KB
testcase_01 AC 112 ms
56,364 KB
testcase_02 AC 114 ms
56,232 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 kaijo8 = kaijo(8);
    static int n;
    public static void main(String[]  args) {
        Scanner sc = new Scanner(System.in);
        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 = kaijo8;
        for (int i = 1; i < 8; i++) {
            if (arr[i] == prev) {
                cnt++;
            } else {
                ans /= kaijo(cnt);
                cnt = 1;
                prev = arr[i];
            }
        }
        ans /= kaijo(cnt);
        total += ans;
    }
    
    static int kaijo(int x) {
        if (x < 2) {
            return 1;
        } else {
            return x * kaijo(x - 1);
        }
    }
    
}
0