結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー nebukuro09nebukuro09
提出日時 2021-07-30 21:44:39
言語 D
(dmd 2.105.2)
結果
AC  
実行時間 1,281 ms / 3,000 ms
コード長 1,264 bytes
コンパイル時間 664 ms
コンパイル使用メモリ 105,728 KB
実行使用メモリ 134,112 KB
最終ジャッジ日時 2023-09-04 13:33:02
合計ジャッジ時間 19,252 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 5 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 6 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1,246 ms
134,024 KB
testcase_15 AC 1,280 ms
133,968 KB
testcase_16 AC 1,281 ms
134,080 KB
testcase_17 AC 1,280 ms
134,056 KB
testcase_18 AC 1,274 ms
133,960 KB
testcase_19 AC 1,276 ms
134,052 KB
testcase_20 AC 1,074 ms
134,020 KB
testcase_21 AC 1,034 ms
134,072 KB
testcase_22 AC 1,084 ms
134,076 KB
testcase_23 AC 1,144 ms
134,068 KB
testcase_24 AC 1,112 ms
134,076 KB
testcase_25 AC 1,103 ms
133,964 KB
testcase_26 AC 6 ms
4,376 KB
testcase_27 AC 926 ms
134,112 KB
testcase_28 AC 392 ms
68,296 KB
testcase_29 AC 377 ms
68,340 KB
testcase_30 AC 563 ms
68,396 KB
testcase_31 AC 901 ms
134,052 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

void main() {
    auto s = readln.split;
    auto N = s[0].to!int;
    auto K = s[1].to!int;
    auto A = 0 ~ readln.split.map!(to!int).array;

    int[] B;
    foreach (i; 1..10) foreach (_; 0..A[i]) B ~= i;

    int[] base = new int[](N+1);
    base[0] = 1;
    foreach (i; 1..N+1) base[i] = base[i-1] * 10 % K;

    auto dp = new long[][](1<<N, K);
    dp[0][0] = 1;
    foreach (mask; 0..1<<N) {
        foreach (i; 0..N) foreach (j; 0..K) {
            if (mask & (1 << i)) continue;
            if (i > 0 && B[i] == B[i-1] && !(mask & (1 << (i-1)))) continue;
            int keta = mask.popcnt;
            int num = base[keta] * B[i] % K + j;
            num %= K;
            dp[(mask | (1 << i))][num] += dp[mask][j];
        }
    }

    dp[(1<<N)-1][0].writeln;
}

long[] solve(int N, int K, int[] A) {
    auto ans = new long[](K);

    do {
        int n = 0;
        int keta = 1;
        foreach (i; 0..N) {
            (n += (keta * A[i] % K)) %= K;
            keta = keta * 10 % K;
        }
        ans[n] += 1;
    } while (nextPermutation(A));

    return ans;
}
0