結果

問題 No.1634 Sorting Integers (Multiple of K) Hard
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2021-07-30 22:31:24
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,242 bytes
コンパイル時間 311 ms
コンパイル使用メモリ 87,312 KB
実行使用メモリ 78,588 KB
最終ジャッジ日時 2023-10-14 05:48:06
合計ジャッジ時間 20,088 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
71,420 KB
testcase_01 AC 80 ms
71,260 KB
testcase_02 AC 78 ms
71,168 KB
testcase_03 AC 111 ms
76,924 KB
testcase_04 TLE -
testcase_05 TLE -
testcase_06 TLE -
testcase_07 TLE -
testcase_08 TLE -
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 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

"""

import sys
from sys import stdin
import math
import itertools

N,K = map(int,stdin.readline().split())
mod = K
c = [0] + list(map(int,stdin.readline().split()))
C = []
for i in range(10):
    for j in range(c[i]):
        C.append(i)

ans = 0
for a in itertools.combinations(C,N//2):

    a = list(a)
    cp = [c[i] for i in range(10)]
    for num in a:
        cp[num] -= 1

    b = []
    for i in range(10):
        for j in range(cp[i]):
            b.append(i)

    #print (a,b)

    adic = {}
    bdic = {}
    
    for p in itertools.permutations(a,len(a)):
        now = 0
        for x in p:
            now *= 10
            now += x
        now %= mod
        if now not in adic:
            adic[now] = 0
        adic[now % mod] += 1

    base = pow(10,len(a),mod)
    for p in itertools.permutations(b,len(b)):
        now = 0
        for x in p:
            now *= 10
            now += x
        now *= base
        now %= mod
        if now not in bdic:
            bdic[now] = 0
        bdic[now % mod] += 1

    #print (a,adic,b,bdic)
    for x in adic:
        y = (mod-x) % mod
        if y in bdic:
            ans += adic[x] * bdic[y]

for i in range(10):
    ans //= math.factorial(c[i])
print (ans)
        
0