結果

問題 No.1330 Multiply or Divide
ユーザー c-yanc-yan
提出日時 2021-01-10 00:46:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 127 ms / 2,000 ms
コード長 825 bytes
コンパイル時間 260 ms
コンパイル使用メモリ 82,040 KB
実行使用メモリ 116,352 KB
最終ジャッジ日時 2024-04-29 18:09:12
合計ジャッジ時間 5,170 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,620 KB
testcase_01 AC 114 ms
113,664 KB
testcase_02 AC 40 ms
54,028 KB
testcase_03 AC 43 ms
54,016 KB
testcase_04 AC 42 ms
53,632 KB
testcase_05 AC 40 ms
53,760 KB
testcase_06 AC 112 ms
109,568 KB
testcase_07 AC 126 ms
113,408 KB
testcase_08 AC 122 ms
115,456 KB
testcase_09 AC 127 ms
115,584 KB
testcase_10 AC 123 ms
115,328 KB
testcase_11 AC 117 ms
115,584 KB
testcase_12 AC 121 ms
115,456 KB
testcase_13 AC 41 ms
53,980 KB
testcase_14 AC 41 ms
54,016 KB
testcase_15 AC 40 ms
53,504 KB
testcase_16 AC 40 ms
53,376 KB
testcase_17 AC 40 ms
53,504 KB
testcase_18 AC 96 ms
112,256 KB
testcase_19 AC 96 ms
112,256 KB
testcase_20 AC 97 ms
112,256 KB
testcase_21 AC 97 ms
112,512 KB
testcase_22 AC 96 ms
112,128 KB
testcase_23 AC 110 ms
116,352 KB
testcase_24 AC 41 ms
53,376 KB
testcase_25 AC 40 ms
53,632 KB
testcase_26 AC 40 ms
53,376 KB
testcase_27 AC 41 ms
53,376 KB
testcase_28 AC 40 ms
53,632 KB
testcase_29 AC 40 ms
53,632 KB
testcase_30 AC 41 ms
53,632 KB
testcase_31 AC 41 ms
53,504 KB
testcase_32 AC 41 ms
53,760 KB
testcase_33 AC 41 ms
53,760 KB
testcase_34 AC 85 ms
99,968 KB
testcase_35 AC 55 ms
71,040 KB
testcase_36 AC 79 ms
95,488 KB
testcase_37 AC 76 ms
92,032 KB
testcase_38 AC 63 ms
79,744 KB
testcase_39 AC 56 ms
72,704 KB
testcase_40 AC 61 ms
75,520 KB
testcase_41 AC 52 ms
67,456 KB
testcase_42 AC 74 ms
88,448 KB
testcase_43 AC 76 ms
92,544 KB
testcase_44 AC 114 ms
109,696 KB
testcase_45 AC 116 ms
109,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

INF = 10 ** 20

N, M, P, *A = map(int, open(0).read().split())

def f(x):
    c = 0
    while x % P == 0:
        c += 1
        x //= P
    return (x, c)

max_A = max(A)

if max_A > M:
    print(1)
    exit()

b = {}
for m, c in map(f, A):
    b.setdefault(c, 0)
    b[c] = max(b[c], m)
for k in list(b):
    if b[k] == 1:
        del b[k]
t = 1
for k in sorted(b):
    if b[k] <= t:
        del b[k]
    else:
        t = b[k]
cs = sorted(b)

if len(cs) == 0:
    print(-1)
    exit()

result = INF
q = deque([(0, 1)])
d = {}
d[0] = 1
while q:
    c, x = q.popleft()
    if x * max_A > M:
        print(c + 1)
        break
    for k in cs:
        d.setdefault(c + 1 + k, 0)
        if x * b[k] > d[c + 1 + k]:
            d[c + 1 + k] = x * b[k]
            q.append((c + 1 + k, x * b[k]))
0