結果

問題 No.1634 Sorting Integers (Multiple of K) Hard
ユーザー ayaoniayaoni
提出日時 2021-07-31 02:09:55
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,421 bytes
コンパイル時間 1,136 ms
コンパイル使用メモリ 86,868 KB
実行使用メモリ 78,692 KB
最終ジャッジ日時 2023-10-14 10:13:04
合計ジャッジ時間 6,164 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import sys
from itertools import permutations
from collections import defaultdict
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())


N,K = MI()
C = [0]+LI()
A = []
for i in range(1,10):
    for _ in range(C[i]):
        A.append(i)

power = [1]
for _ in range(N):
    power.append((power[-1]*10) % K)

N0,N1 = N//2,N-N//2
ans = 0
for i in range(1<<N):
    X,Y = [],[]
    for j in range(N):
        if (i>>j) & 1:
            X.append(A[j])
        else:
            Y.append(A[j])
    if len(X) != N0:
        continue

    dic_X = defaultdict(int)
    for Z in permutations(X,N0):
        x = 0
        for j in range(N0):
            x += Z[j]*power[j]
            x %= K
        dic_X[x] += 1
    dic_Y = defaultdict(int)
    for Z in permutations(Y,N1):
        y = 0
        for j in range(N1):
            y += Z[j]*power[j]
            y %= K
        dic_Y[y] += 1

    for k in dic_X.keys():
        ans += dic_X[k]*dic_Y[(-k*power[N1]) % K]

for i in range(1,10):
    for j in range(C[i]):
        ans //= j+1

print(ans)
0