結果

問題 No.1330 Multiply or Divide
ユーザー c-yanc-yan
提出日時 2021-01-10 01:05:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 523 ms / 2,000 ms
コード長 786 bytes
コンパイル時間 157 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 32,888 KB
最終ジャッジ日時 2024-04-29 18:56:42
合計ジャッジ時間 6,092 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,752 KB
testcase_01 AC 231 ms
29,508 KB
testcase_02 AC 29 ms
10,752 KB
testcase_03 AC 27 ms
10,880 KB
testcase_04 AC 26 ms
10,880 KB
testcase_05 AC 25 ms
10,880 KB
testcase_06 AC 218 ms
14,120 KB
testcase_07 AC 523 ms
29,516 KB
testcase_08 AC 241 ms
32,736 KB
testcase_09 AC 258 ms
32,612 KB
testcase_10 AC 247 ms
32,864 KB
testcase_11 AC 227 ms
32,608 KB
testcase_12 AC 249 ms
32,612 KB
testcase_13 AC 30 ms
11,008 KB
testcase_14 AC 29 ms
10,880 KB
testcase_15 AC 27 ms
10,880 KB
testcase_16 AC 26 ms
10,752 KB
testcase_17 AC 26 ms
10,752 KB
testcase_18 AC 92 ms
32,740 KB
testcase_19 AC 90 ms
32,860 KB
testcase_20 AC 94 ms
32,740 KB
testcase_21 AC 92 ms
32,740 KB
testcase_22 AC 95 ms
32,608 KB
testcase_23 AC 237 ms
32,888 KB
testcase_24 AC 27 ms
10,880 KB
testcase_25 AC 26 ms
10,880 KB
testcase_26 AC 26 ms
11,008 KB
testcase_27 AC 27 ms
10,752 KB
testcase_28 AC 26 ms
10,880 KB
testcase_29 AC 26 ms
10,880 KB
testcase_30 AC 26 ms
11,008 KB
testcase_31 AC 27 ms
10,880 KB
testcase_32 AC 27 ms
11,008 KB
testcase_33 AC 27 ms
10,880 KB
testcase_34 AC 76 ms
27,096 KB
testcase_35 AC 40 ms
15,120 KB
testcase_36 AC 67 ms
25,124 KB
testcase_37 AC 66 ms
23,684 KB
testcase_38 AC 51 ms
18,892 KB
testcase_39 AC 42 ms
16,456 KB
testcase_40 AC 45 ms
17,448 KB
testcase_41 AC 36 ms
14,060 KB
testcase_42 AC 63 ms
22,732 KB
testcase_43 AC 68 ms
24,592 KB
testcase_44 AC 215 ms
13,992 KB
testcase_45 AC 225 ms
14,120 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