結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー mkawa2mkawa2
提出日時 2021-07-31 15:36:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,225 ms / 3,000 ms
コード長 1,346 bytes
コンパイル時間 301 ms
コンパイル使用メモリ 86,952 KB
実行使用メモリ 206,736 KB
最終ジャッジ日時 2023-10-14 15:00:12
合計ジャッジ時間 14,428 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
71,232 KB
testcase_01 AC 70 ms
71,188 KB
testcase_02 AC 71 ms
71,328 KB
testcase_03 AC 98 ms
76,776 KB
testcase_04 AC 68 ms
71,420 KB
testcase_05 AC 71 ms
71,276 KB
testcase_06 AC 67 ms
71,160 KB
testcase_07 AC 70 ms
75,800 KB
testcase_08 AC 68 ms
75,556 KB
testcase_09 AC 87 ms
76,688 KB
testcase_10 AC 87 ms
76,580 KB
testcase_11 AC 80 ms
76,932 KB
testcase_12 AC 74 ms
76,432 KB
testcase_13 AC 78 ms
76,672 KB
testcase_14 AC 743 ms
200,644 KB
testcase_15 AC 1,063 ms
206,460 KB
testcase_16 AC 1,082 ms
206,736 KB
testcase_17 AC 1,088 ms
206,504 KB
testcase_18 AC 1,207 ms
206,384 KB
testcase_19 AC 1,225 ms
206,592 KB
testcase_20 AC 284 ms
205,876 KB
testcase_21 AC 267 ms
191,064 KB
testcase_22 AC 288 ms
204,484 KB
testcase_23 AC 314 ms
204,568 KB
testcase_24 AC 300 ms
204,232 KB
testcase_25 AC 294 ms
203,240 KB
testcase_26 AC 111 ms
78,900 KB
testcase_27 AC 560 ms
170,976 KB
testcase_28 AC 352 ms
117,096 KB
testcase_29 AC 242 ms
117,940 KB
testcase_30 AC 381 ms
136,624 KB
testcase_31 AC 558 ms
169,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = 10**16
# md = 998244353
md = 10**9+7

n, k = LI()
ac = LI()

ten = [1]
for _ in range(n): ten.append(ten[-1]*10%k)

aa = []
for a, c in enumerate(ac, 1):
    aa += [a]*c

dp = [[0]*k for _ in range(1 << n)]
dp[0][0] = 1

popcnt = lambda x: bin(x).count("1")

def ng(s, j):
    a = aa[j]
    for i in range(j-1, -1, -1):
        if aa[i] == a:
            if s >> i & 1 == 0: return True
        else:
            break
    return False

for s in range(1 << n):
    c = popcnt(s)
    for r in range(k):
        pre = dp[s][r]
        if pre == 0: continue
        for j, a in enumerate(aa):
            if s >> j & 1: continue
            if ng(s, j): continue
            ns = s | 1 << j
            nr = (r+a*ten[c])%k
            dp[ns][nr] += pre

print(dp[-1][0])
0