結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー ygd.ygd.
提出日時 2021-07-30 23:45:46
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,108 bytes
コンパイル時間 291 ms
コンパイル使用メモリ 87,080 KB
実行使用メモリ 81,360 KB
最終ジャッジ日時 2023-10-14 08:52:15
合計ジャッジ時間 6,670 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
77,036 KB
testcase_01 AC 79 ms
77,016 KB
testcase_02 AC 77 ms
77,004 KB
testcase_03 AC 99 ms
77,992 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 AC 78 ms
77,136 KB
testcase_07 AC 77 ms
77,096 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 AC 82 ms
78,128 KB
testcase_11 AC 86 ms
78,016 KB
testcase_12 RE -
testcase_13 AC 86 ms
77,812 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    N,K = map(int,input().split())
    #global K
    C = list(map(int,input().split()))
    A = []
    for i in range(N):
        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