結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー tcltktcltk
提出日時 2021-09-11 02:50:23
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,220 bytes
コンパイル時間 1,459 ms
コンパイル使用メモリ 87,252 KB
実行使用メモリ 190,036 KB
最終ジャッジ日時 2023-09-03 22:06:06
合計ジャッジ時間 12,663 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 202 ms
81,056 KB
testcase_01 AC 200 ms
80,848 KB
testcase_02 AC 201 ms
81,112 KB
testcase_03 AC 278 ms
85,376 KB
testcase_04 AC 204 ms
80,876 KB
testcase_05 AC 203 ms
80,904 KB
testcase_06 AC 203 ms
81,024 KB
testcase_07 AC 202 ms
81,052 KB
testcase_08 AC 205 ms
81,064 KB
testcase_09 AC 231 ms
84,672 KB
testcase_10 AC 232 ms
84,364 KB
testcase_11 AC 234 ms
84,752 KB
testcase_12 AC 224 ms
84,340 KB
testcase_13 AC 225 ms
84,356 KB
testcase_14 TLE -
testcase_15 TLE -
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 #

#!/usr/bin/env python3
# from typing import *

import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq


def input():
    return sys.stdin.readline()[:-1]


# sys.setrecursionlimit(1000000)

# _INPUT = """3 2
# 1 2 0 0 0 0 0 0 0
# """
# sys.stdin = io.StringIO(_INPUT)

INF = 10**10

def get_count(mask, i):
    for j in range(i):
        mask //= (C[j]+1)
    n = mask % (C[i]+1)
    return n

def set_count(mask, i, n):
    k = 1
    for j in range(i):
        k *= (C[j]+1)
    mask1 = (mask // (k * (C[i]+1)) * (C[i]+1) + n) * k + (mask % k)
    return mask1
    


N, K = map(int, input().split())
C = list(map(int, input().split()))

M = 1
for i in range(9):
    M *= (C[i]+1)

A = []
for i in range(9):
    A += [i+1] * C[i]

dp = [collections.defaultdict(int) for _ in range(M)]
dp[0][0] = 1
for mask in range(M):
    for r in dp[mask].keys():
        if dp[mask][r] == 0:
            continue
        for i in range(9):
            n = get_count(mask, i)
            if n == C[i]:
                continue
            mask1 = set_count(mask, i, n+1)
            r1 = (10*r+(i+1)) % K
            dp[mask1][r1] += dp[mask][r]

ans = dp[(M)-1][0]
print(ans)
0