結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー ygd.ygd.
提出日時 2021-07-30 23:46:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,530 ms / 3,000 ms
コード長 1,110 bytes
コンパイル時間 264 ms
コンパイル使用メモリ 87,144 KB
実行使用メモリ 207,796 KB
最終ジャッジ日時 2023-10-14 08:53:56
合計ジャッジ時間 39,242 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
76,804 KB
testcase_01 AC 76 ms
76,912 KB
testcase_02 AC 79 ms
77,000 KB
testcase_03 AC 95 ms
78,020 KB
testcase_04 AC 78 ms
76,884 KB
testcase_05 AC 77 ms
77,040 KB
testcase_06 AC 76 ms
76,992 KB
testcase_07 AC 78 ms
76,988 KB
testcase_08 AC 80 ms
77,544 KB
testcase_09 AC 90 ms
77,548 KB
testcase_10 AC 84 ms
77,920 KB
testcase_11 AC 85 ms
77,580 KB
testcase_12 AC 82 ms
77,368 KB
testcase_13 AC 85 ms
77,544 KB
testcase_14 AC 2,415 ms
202,220 KB
testcase_15 AC 2,527 ms
207,612 KB
testcase_16 AC 2,530 ms
207,684 KB
testcase_17 AC 2,522 ms
207,760 KB
testcase_18 AC 2,514 ms
207,576 KB
testcase_19 AC 2,520 ms
207,672 KB
testcase_20 AC 2,520 ms
207,796 KB
testcase_21 AC 2,230 ms
192,336 KB
testcase_22 AC 2,479 ms
205,480 KB
testcase_23 AC 2,478 ms
205,612 KB
testcase_24 AC 2,483 ms
205,384 KB
testcase_25 AC 2,452 ms
204,116 KB
testcase_26 AC 89 ms
77,708 KB
testcase_27 AC 1,848 ms
171,876 KB
testcase_28 AC 860 ms
118,748 KB
testcase_29 AC 875 ms
119,480 KB
testcase_30 AC 1,210 ms
137,364 KB
testcase_31 AC 1,846 ms
171,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    N,K = map(int,input().split())
    #global K
    C = list(map(int,input().split()))
    A = []
    for i in range(9):
        for j in range(C[i]):
            A.append(i+1)
    #print(A)
    MAX = 200000
    popcount = [0]*MAX
    for i in range(1,MAX):
        popcount[i] = popcount[i//2] + i%2
    
    #print(popcount)
    #dp[mask][j]:maskを使った時の余りがj
    dp = [[0]*(K) for _ in range(1<<N)]
    dp[0][0] = 1 #何もない場合の数は1
    for mask in range(1<<N):
        pcnt = popcount[mask] #この個数入っている
        #print("mask",mask,"pct",pcnt)
        base = pow(10,pcnt)
        for i in range(N):
            if (mask>>i)&1 == 1: continue #既に含まれている
            val = A[i]*base%K
            for j in range(K):
                #print(mask|1<<i,mask,val,base)
                dp[mask|1<<i][(j+val)%K] += dp[mask][j]
    #print(dp)
    ans = dp[-1][0]
    fact = [1] #fact[n]: n!
    for i in range(1,N+1):
        fact.append(fact[-1]*i)
    for c in C:
        ans //= fact[c]

    print(ans)



if __name__ == '__main__':
    main()
0