結果

問題 No.1330 Multiply or Divide
ユーザー c-yanc-yan
提出日時 2021-01-10 00:44:21
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 811 bytes
コンパイル時間 208 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 32,868 KB
最終ジャッジ日時 2024-04-29 18:01:53
合計ジャッジ時間 7,000 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,880 KB
testcase_01 AC 279 ms
29,376 KB
testcase_02 AC 29 ms
10,752 KB
testcase_03 AC 29 ms
10,880 KB
testcase_04 AC 28 ms
10,880 KB
testcase_05 AC 28 ms
10,880 KB
testcase_06 AC 236 ms
14,492 KB
testcase_07 AC 584 ms
29,636 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 AC 100 ms
32,604 KB
testcase_19 AC 100 ms
32,476 KB
testcase_20 AC 99 ms
32,736 KB
testcase_21 AC 103 ms
32,600 KB
testcase_22 AC 102 ms
32,608 KB
testcase_23 AC 266 ms
32,512 KB
testcase_24 AC 30 ms
10,880 KB
testcase_25 AC 29 ms
10,752 KB
testcase_26 RE -
testcase_27 AC 28 ms
10,624 KB
testcase_28 AC 29 ms
10,880 KB
testcase_29 AC 29 ms
10,752 KB
testcase_30 AC 28 ms
10,624 KB
testcase_31 AC 28 ms
11,008 KB
testcase_32 AC 28 ms
10,880 KB
testcase_33 AC 28 ms
10,880 KB
testcase_34 AC 84 ms
27,092 KB
testcase_35 AC 44 ms
14,996 KB
testcase_36 AC 76 ms
25,120 KB
testcase_37 AC 71 ms
23,612 KB
testcase_38 AC 56 ms
18,716 KB
testcase_39 AC 48 ms
16,332 KB
testcase_40 AC 51 ms
17,316 KB
testcase_41 AC 40 ms
14,180 KB
testcase_42 AC 66 ms
22,736 KB
testcase_43 AC 75 ms
24,588 KB
testcase_44 AC 244 ms
14,652 KB
testcase_45 AC 239 ms
14,672 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]
    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