結果
問題 |
No.1634 Sorting Integers (Multiple of K) Hard
|
ユーザー |
![]() |
提出日時 | 2021-07-31 02:09:55 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,421 bytes |
コンパイル時間 | 158 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 131,200 KB |
最終ジャッジ日時 | 2024-09-16 05:10:18 |
合計ジャッジ時間 | 14,045 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | TLE * 4 -- * 24 |
ソースコード
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)