結果

問題 No.1330 Multiply or Divide
ユーザー c-yanc-yan
提出日時 2021-01-10 01:05:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 786 bytes
コンパイル時間 180 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 115,712 KB
最終ジャッジ日時 2024-04-29 18:57:41
合計ジャッジ時間 5,956 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
52,480 KB
testcase_01 AC 117 ms
113,280 KB
testcase_02 AC 43 ms
52,352 KB
testcase_03 AC 45 ms
52,096 KB
testcase_04 AC 45 ms
52,608 KB
testcase_05 AC 48 ms
52,480 KB
testcase_06 AC 126 ms
109,312 KB
testcase_07 AC 137 ms
113,152 KB
testcase_08 AC 135 ms
115,584 KB
testcase_09 AC 142 ms
115,456 KB
testcase_10 AC 136 ms
115,712 KB
testcase_11 AC 133 ms
115,456 KB
testcase_12 AC 132 ms
115,584 KB
testcase_13 AC 44 ms
52,480 KB
testcase_14 AC 43 ms
52,608 KB
testcase_15 AC 43 ms
52,480 KB
testcase_16 AC 43 ms
52,352 KB
testcase_17 AC 43 ms
52,352 KB
testcase_18 AC 105 ms
110,976 KB
testcase_19 AC 106 ms
111,104 KB
testcase_20 AC 106 ms
110,976 KB
testcase_21 AC 106 ms
110,848 KB
testcase_22 AC 107 ms
110,848 KB
testcase_23 AC 115 ms
113,792 KB
testcase_24 AC 44 ms
52,480 KB
testcase_25 AC 42 ms
52,608 KB
testcase_26 AC 44 ms
52,224 KB
testcase_27 AC 43 ms
52,352 KB
testcase_28 AC 42 ms
52,352 KB
testcase_29 AC 42 ms
52,608 KB
testcase_30 AC 42 ms
52,352 KB
testcase_31 AC 43 ms
52,352 KB
testcase_32 AC 43 ms
52,224 KB
testcase_33 AC 45 ms
52,096 KB
testcase_34 AC 93 ms
98,688 KB
testcase_35 AC 61 ms
69,888 KB
testcase_36 AC 88 ms
94,208 KB
testcase_37 AC 83 ms
90,240 KB
testcase_38 AC 70 ms
78,208 KB
testcase_39 AC 63 ms
71,040 KB
testcase_40 AC 67 ms
74,496 KB
testcase_41 AC 57 ms
66,432 KB
testcase_42 AC 81 ms
87,552 KB
testcase_43 AC 85 ms
91,648 KB
testcase_44 AC 127 ms
109,184 KB
testcase_45 AC 124 ms
109,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop, heappush

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)
t = 1
for k in sorted(b):
    if b[k] <= t:
        del b[k]
    else:
        t = b[k]

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

q = [(0, 1)]
max_x = {}
max_x[0] = 1
while q:
    c, x = heappop(q)
    if max_x[c] > x:
        continue
    if x * max_A > M:
        print(c + 1)
        break
    for k in b:
        nc = c + 1 + k
        nx = x * b[k]
        max_x.setdefault(nc, 0)
        if nx > max_x[nc]:
            max_x[nc] = nx
            heappush(q, (nc, nx))
0