結果
| 問題 |
No.1634 Sorting Integers (Multiple of K) Hard
|
| コンテスト | |
| ユーザー |
👑 SPD_9X2
|
| 提出日時 | 2021-07-30 22:31:24 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,242 bytes |
| コンパイル時間 | 176 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 118,912 KB |
| 最終ジャッジ日時 | 2024-09-16 01:05:51 |
| 合計ジャッジ時間 | 19,153 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | TLE * 5 -- * 23 |
ソースコード
"""
"""
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)
SPD_9X2