結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー ygd.ygd.
提出日時 2021-07-30 22:23:20
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,152 bytes
コンパイル時間 150 ms
コンパイル使用メモリ 10,968 KB
実行使用メモリ 38,256 KB
最終ジャッジ日時 2023-10-14 05:34:27
合計ジャッジ時間 6,231 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
14,812 KB
testcase_01 AC 44 ms
10,344 KB
testcase_02 AC 43 ms
10,332 KB
testcase_03 AC 128 ms
10,924 KB
testcase_04 AC 43 ms
10,364 KB
testcase_05 AC 43 ms
10,392 KB
testcase_06 AC 43 ms
10,404 KB
testcase_07 AC 42 ms
10,324 KB
testcase_08 AC 45 ms
10,364 KB
testcase_09 AC 89 ms
10,568 KB
testcase_10 AC 45 ms
10,452 KB
testcase_11 AC 55 ms
10,348 KB
testcase_12 AC 50 ms
10,344 KB
testcase_13 AC 44 ms
10,356 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()


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