結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー tentententen
提出日時 2022-08-18 17:18:36
言語 Java21
(openjdk 21)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,021 bytes
コンパイル時間 2,355 ms
コンパイル使用メモリ 78,020 KB
実行使用メモリ 187,960 KB
最終ジャッジ日時 2024-04-16 01:27:09
合計ジャッジ時間 10,444 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
36,948 KB
testcase_01 AC 53 ms
37,156 KB
testcase_02 AC 53 ms
37,220 KB
testcase_03 AC 63 ms
37,620 KB
testcase_04 AC 53 ms
37,216 KB
testcase_05 AC 51 ms
37,120 KB
testcase_06 AC 52 ms
37,280 KB
testcase_07 AC 54 ms
37,032 KB
testcase_08 AC 55 ms
36,956 KB
testcase_09 AC 57 ms
37,884 KB
testcase_10 AC 53 ms
37,056 KB
testcase_11 AC 55 ms
37,100 KB
testcase_12 AC 54 ms
37,152 KB
testcase_13 AC 54 ms
37,024 KB
testcase_14 AC 2,116 ms
179,308 KB
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 AC 413 ms
182,180 KB
testcase_21 AC 538 ms
181,700 KB
testcase_22 AC 697 ms
181,952 KB
testcase_23 AC 1,585 ms
181,812 KB
testcase_24 AC 1,042 ms
181,972 KB
testcase_25 AC 873 ms
180,864 KB
testcase_26 AC 81 ms
38,088 KB
testcase_27 AC 2,543 ms
131,828 KB
testcase_28 AC 1,103 ms
77,804 KB
testcase_29 AC 969 ms
78,424 KB
testcase_30 AC 1,490 ms
100,980 KB
testcase_31 AC 2,535 ms
131,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    static int n;
    static int k;
    static long[][] dp;
    static int[] values;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        n = sc.nextInt();
        k = sc.nextInt();
        values = new int[n];
        int idx = 0;
        long div = 1;
        for (int i = 1; i <= 9; i++) {
            int x = sc.nextInt();
            for (int j = 0; j < x; j++) {
                values[idx++] = i;
            }
            div *= proc(x);
        }
        dp = new long[1 << n][k];
        for (long[] arr : dp) {
            Arrays.fill(arr, -1);
        }
        Arrays.fill(dp[0], 0);
        dp[0][0] = 1;
        System.out.println(dfw((1 << n) - 1, 0) / div);
    }
    
    static long proc(int x) {
        if (x == 0) {
            return 1;
        } else {
            return x * proc(x - 1);
        }
    }
    
    static long dfw(int mask, int mod) {
        if (dp[mask][mod] < 0) {
            dp[mask][mod] = 0;
            for (int i = 0; i < n; i++) {
                if ((mask & (1 << i)) == 0) {
                    continue;
                }
                dp[mask][mod] += dfw(mask ^ (1 << i), (mod * 10 + values[i]) % k);
            }
        }
        return dp[mask][mod];
    }
}

class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0