結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー tentententen
提出日時 2024-01-11 13:47:08
言語 Java21
(openjdk 21)
結果
AC  
実行時間 729 ms / 3,000 ms
コード長 2,249 bytes
コンパイル時間 2,604 ms
コンパイル使用メモリ 87,472 KB
実行使用メモリ 200,088 KB
最終ジャッジ日時 2024-01-11 13:47:21
合計ジャッジ時間 12,682 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
53,996 KB
testcase_01 AC 52 ms
53,976 KB
testcase_02 AC 52 ms
53,996 KB
testcase_03 AC 63 ms
54,264 KB
testcase_04 AC 52 ms
53,976 KB
testcase_05 AC 52 ms
54,012 KB
testcase_06 AC 52 ms
53,984 KB
testcase_07 AC 53 ms
53,992 KB
testcase_08 AC 53 ms
53,988 KB
testcase_09 AC 63 ms
54,236 KB
testcase_10 AC 52 ms
53,988 KB
testcase_11 AC 56 ms
53,992 KB
testcase_12 AC 55 ms
53,988 KB
testcase_13 AC 52 ms
53,988 KB
testcase_14 AC 729 ms
195,240 KB
testcase_15 AC 521 ms
200,080 KB
testcase_16 AC 525 ms
195,068 KB
testcase_17 AC 514 ms
200,064 KB
testcase_18 AC 539 ms
200,024 KB
testcase_19 AC 514 ms
195,092 KB
testcase_20 AC 414 ms
200,088 KB
testcase_21 AC 417 ms
199,936 KB
testcase_22 AC 418 ms
199,936 KB
testcase_23 AC 477 ms
199,948 KB
testcase_24 AC 435 ms
194,880 KB
testcase_25 AC 440 ms
199,932 KB
testcase_26 AC 76 ms
54,752 KB
testcase_27 AC 382 ms
146,840 KB
testcase_28 AC 209 ms
92,780 KB
testcase_29 AC 206 ms
93,004 KB
testcase_30 AC 277 ms
117,724 KB
testcase_31 AC 375 ms
144,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int target = sc.nextInt();
        int[] values = new int[n];
        int idx = 0;
        for (int i = 1; i <= 9; i++) {
            int x = sc.nextInt();
            for (int j = 0; j < x; j++) {
                values[idx++] = i;
            }
        }
        long[][] dp = new long[1 << n][target];
        dp[0][0] = 1;
        for (int i = 1; i < (1 << n); i++) {
            for (int j = 0; j < n; j++) {
                if ((i & (1 << j)) == 0 || (j > 0 && values[j - 1] == values[j] && (i & (1 << (j - 1))) > 0)) {
                    continue;
                }
                for (int k = 0; k < target; k++) {
                    dp[i][(k * 10 + values[j]) % target] += dp[i ^ (1 << j)][k];
                }
            }
        }
        System.out.println(dp[(1 << n) - 1][0]);
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    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 int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0