結果

問題 No.1330 Multiply or Divide
ユーザー U SU S
提出日時 2021-01-08 22:21:15
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,198 bytes
コンパイル時間 132 ms
コンパイル使用メモリ 81,940 KB
実行使用メモリ 117,540 KB
最終ジャッジ日時 2024-04-28 03:38:40
合計ジャッジ時間 5,862 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
60,160 KB
testcase_01 AC 165 ms
112,176 KB
testcase_02 WA -
testcase_03 AC 45 ms
61,608 KB
testcase_04 AC 43 ms
61,236 KB
testcase_05 AC 44 ms
60,848 KB
testcase_06 AC 80 ms
101,972 KB
testcase_07 AC 126 ms
112,384 KB
testcase_08 AC 150 ms
117,168 KB
testcase_09 AC 152 ms
117,144 KB
testcase_10 AC 155 ms
117,020 KB
testcase_11 AC 154 ms
116,920 KB
testcase_12 AC 154 ms
117,148 KB
testcase_13 AC 46 ms
61,248 KB
testcase_14 AC 45 ms
62,560 KB
testcase_15 AC 45 ms
62,340 KB
testcase_16 AC 46 ms
60,996 KB
testcase_17 AC 45 ms
60,596 KB
testcase_18 AC 155 ms
116,916 KB
testcase_19 AC 159 ms
117,164 KB
testcase_20 AC 164 ms
117,020 KB
testcase_21 AC 158 ms
117,048 KB
testcase_22 AC 158 ms
116,784 KB
testcase_23 WA -
testcase_24 AC 46 ms
61,844 KB
testcase_25 AC 46 ms
62,092 KB
testcase_26 WA -
testcase_27 AC 46 ms
61,588 KB
testcase_28 AC 45 ms
60,248 KB
testcase_29 AC 45 ms
60,596 KB
testcase_30 AC 46 ms
62,692 KB
testcase_31 AC 44 ms
61,784 KB
testcase_32 AC 43 ms
60,784 KB
testcase_33 AC 46 ms
62,088 KB
testcase_34 AC 131 ms
104,896 KB
testcase_35 AC 71 ms
79,248 KB
testcase_36 AC 119 ms
98,120 KB
testcase_37 AC 117 ms
96,036 KB
testcase_38 AC 86 ms
90,332 KB
testcase_39 AC 77 ms
81,408 KB
testcase_40 AC 82 ms
85,892 KB
testcase_41 AC 64 ms
75,136 KB
testcase_42 AC 132 ms
93,892 KB
testcase_43 AC 114 ms
96,336 KB
testcase_44 AC 104 ms
104,908 KB
testcase_45 AC 106 ms
104,956 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# import sys
# input = sys.stdin.readline
def mp():return map(int,input().split())
def lmp():return list(map(int,input().split()))
import math
import bisect
from copy import deepcopy as dc
from itertools import accumulate
from collections import Counter, defaultdict, deque
def ceil(U,V):return (U+V-1)//V
def modf1(N,MOD):return (N-1)%MOD+1

n,m,p = mp()
a = lmp()
if m == 1:
    print(0)
    exit()
m = ceil(m,max(a))
ag = []
for i in range(n):
    if math.gcd(a[i], p) == 1 and a[i] != 1:
        ag.append((a[i],1))
    else:
        cnt = 0
        while True:
            if a[i] % p == 0:
                cnt += 1
                a[i] //= p
            else:
                break
        if a[i] != 1:
            ag.append((a[i],1+cnt))
if not ag:
    print(-1)
    exit()
d = defaultdict(lambda:0)
for i in range(len(ag)):
    d[ag[i][1]] = max(d[ag[i][1]], ag[i][0])
d = list(d.items())  # 操作回数 かける数
stack = [(1,1)]  #今の数 操作回数
ans = int(1e10)
#print(d)
while stack:
    now = stack.pop()
    if now[0] >= m:
        ans = min(ans,now[1])
        #print(now)
    else:
        for i,j in d:
            stack.append((now[0]*j, now[1]+i))
print(ans)





0