結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー とりゐとりゐ
提出日時 2021-07-08 15:37:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,001 ms / 3,000 ms
コード長 680 bytes
コンパイル時間 328 ms
コンパイル使用メモリ 87,020 KB
実行使用メモリ 206,788 KB
最終ジャッジ日時 2023-10-14 02:12:34
合計ジャッジ時間 24,754 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,264 KB
testcase_01 AC 71 ms
71,128 KB
testcase_02 AC 72 ms
70,948 KB
testcase_03 AC 92 ms
76,816 KB
testcase_04 AC 76 ms
71,264 KB
testcase_05 AC 72 ms
71,124 KB
testcase_06 AC 75 ms
71,288 KB
testcase_07 AC 74 ms
71,096 KB
testcase_08 AC 78 ms
75,956 KB
testcase_09 AC 84 ms
76,188 KB
testcase_10 AC 79 ms
76,196 KB
testcase_11 AC 81 ms
76,400 KB
testcase_12 AC 79 ms
75,692 KB
testcase_13 AC 80 ms
76,564 KB
testcase_14 AC 1,915 ms
200,692 KB
testcase_15 AC 2,001 ms
206,680 KB
testcase_16 AC 2,001 ms
206,460 KB
testcase_17 AC 2,000 ms
206,452 KB
testcase_18 AC 1,998 ms
206,360 KB
testcase_19 AC 1,999 ms
206,788 KB
testcase_20 AC 263 ms
206,344 KB
testcase_21 AC 241 ms
183,216 KB
testcase_22 AC 445 ms
204,156 KB
testcase_23 AC 1,644 ms
204,340 KB
testcase_24 AC 935 ms
204,300 KB
testcase_25 AC 394 ms
202,844 KB
testcase_26 AC 126 ms
78,988 KB
testcase_27 AC 1,453 ms
170,716 KB
testcase_28 AC 711 ms
117,312 KB
testcase_29 AC 771 ms
118,064 KB
testcase_30 AC 1,006 ms
136,580 KB
testcase_31 AC 1,457 ms
170,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import itertools
n,p=map(int,input().split())
c1=list(map(int,input().split()))
c2=[]
for i in range(9):
  c2.append([c1[i],i])
c2.sort(reverse=True)
q=[1]*n
for i in range(1,n):
  q[i]=(q[i-1]*10)%p
d=set([0])
memo=[[0]*p for i in range(2**n)]
memo[0][0]=1
for a in range(9):
  i=c2[a][1]
  if c1[i]==0:
    continue
  e=set()
  for j in d:
    t=[]
    for k in range(n):
      if (j>>k)&1==0:
        t.append(k)
    all=itertools.combinations(t,c1[i])
    for x in all:
      y=j
      cnt=0
      for k in x:
        cnt+=q[k]
        y+=2**k
      for k in range(p):
        s=(cnt*(i+1)+k)%p
        memo[y][s]+=memo[j][k]
      e.add(y)
  d=e.copy()
print(memo[2**n-1][0])
0