結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー tcltktcltk
提出日時 2021-09-11 02:47:32
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,192 bytes
コンパイル時間 301 ms
コンパイル使用メモリ 87,020 KB
実行使用メモリ 113,788 KB
最終ジャッジ日時 2023-09-03 21:55:56
合計ジャッジ時間 12,350 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 206 ms
81,008 KB
testcase_01 AC 201 ms
80,552 KB
testcase_02 AC 200 ms
80,476 KB
testcase_03 AC 258 ms
84,844 KB
testcase_04 AC 198 ms
80,768 KB
testcase_05 AC 199 ms
80,800 KB
testcase_06 AC 198 ms
80,572 KB
testcase_07 AC 201 ms
81,400 KB
testcase_08 AC 203 ms
81,092 KB
testcase_09 AC 230 ms
84,608 KB
testcase_10 AC 231 ms
84,136 KB
testcase_11 AC 233 ms
84,156 KB
testcase_12 AC 224 ms
84,116 KB
testcase_13 AC 218 ms
84,144 KB
testcase_14 AC 2,692 ms
113,788 KB
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 = [[0] * K for _ in range(M)]
dp[0][0] = 1
for mask in range(M):
    for r in range(K):
        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