結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー ygd.ygd.
提出日時 2021-07-30 22:12:01
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,772 bytes
コンパイル時間 1,307 ms
コンパイル使用メモリ 86,636 KB
実行使用メモリ 83,860 KB
最終ジャッジ日時 2023-10-14 05:07:14
合計ジャッジ時間 9,779 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
78,908 KB
testcase_01 AC 128 ms
78,752 KB
testcase_02 AC 129 ms
78,932 KB
testcase_03 AC 318 ms
83,860 KB
testcase_04 AC 127 ms
78,960 KB
testcase_05 AC 125 ms
78,988 KB
testcase_06 AC 124 ms
78,808 KB
testcase_07 AC 130 ms
79,276 KB
testcase_08 AC 144 ms
82,132 KB
testcase_09 AC 220 ms
82,816 KB
testcase_10 AC 151 ms
82,236 KB
testcase_11 AC 164 ms
82,236 KB
testcase_12 AC 155 ms
82,380 KB
testcase_13 AC 151 ms
82,868 KB
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import copy
import sys
sys.setrecursionlimit(1000000)
from functools import lru_cache


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

    @lru_cache(maxsize=None)
    def solve(X): #Xというタプルまで見た時次の遷移
        X = list(X)
        pcnt = 0
        for a in X:
            pcnt += a
        if pcnt == 0:
            ret = [0]*K
            ret[0] = 1
            return ret
        base = pow(10,pcnt-1)
        ret = [0]*K
        for i in range(9):
            if X[i] >= 1:
                val = base*(i+1)
                TX = copy.copy(X)
                TX[i] -= 1
                TX = tuple(TX)
                for i in range(K):
                    temp = solve(TX)
                    ret[(i+val)%K] += temp[i]
        #print(X,ret)
        return ret


    d = solve(tuple(C))
    print(d[0])
    exit()
    #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]
    print(ans)


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