結果

問題 No.1330 Multiply or Divide
ユーザー U SU S
提出日時 2021-01-08 22:55:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 210 ms / 2,000 ms
コード長 1,317 bytes
コンパイル時間 168 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 117,692 KB
最終ジャッジ日時 2024-04-28 06:23:26
合計ジャッジ時間 6,685 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
60,416 KB
testcase_01 AC 208 ms
108,208 KB
testcase_02 AC 55 ms
60,416 KB
testcase_03 AC 56 ms
60,672 KB
testcase_04 AC 55 ms
60,544 KB
testcase_05 AC 55 ms
60,544 KB
testcase_06 AC 132 ms
104,704 KB
testcase_07 AC 173 ms
108,092 KB
testcase_08 AC 207 ms
117,688 KB
testcase_09 AC 210 ms
113,848 KB
testcase_10 AC 207 ms
115,000 KB
testcase_11 AC 205 ms
117,448 KB
testcase_12 AC 206 ms
117,692 KB
testcase_13 AC 55 ms
61,056 KB
testcase_14 AC 56 ms
60,672 KB
testcase_15 AC 57 ms
60,672 KB
testcase_16 AC 55 ms
60,800 KB
testcase_17 AC 56 ms
60,672 KB
testcase_18 AC 146 ms
112,452 KB
testcase_19 AC 146 ms
112,312 KB
testcase_20 AC 145 ms
112,316 KB
testcase_21 AC 144 ms
112,384 KB
testcase_22 AC 147 ms
112,324 KB
testcase_23 AC 173 ms
114,116 KB
testcase_24 AC 55 ms
60,544 KB
testcase_25 AC 56 ms
60,544 KB
testcase_26 AC 56 ms
60,672 KB
testcase_27 AC 55 ms
60,288 KB
testcase_28 AC 55 ms
60,672 KB
testcase_29 AC 54 ms
60,416 KB
testcase_30 AC 54 ms
60,416 KB
testcase_31 AC 55 ms
60,544 KB
testcase_32 AC 54 ms
60,544 KB
testcase_33 AC 55 ms
60,416 KB
testcase_34 AC 129 ms
103,320 KB
testcase_35 AC 86 ms
82,688 KB
testcase_36 AC 116 ms
97,408 KB
testcase_37 AC 112 ms
95,744 KB
testcase_38 AC 96 ms
87,552 KB
testcase_39 AC 89 ms
83,072 KB
testcase_40 AC 92 ms
84,864 KB
testcase_41 AC 77 ms
78,080 KB
testcase_42 AC 107 ms
93,184 KB
testcase_43 AC 112 ms
95,488 KB
testcase_44 AC 157 ms
104,320 KB
testcase_45 AC 157 ms
104,192 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()
ac = dc(a)
if m < max(a):
    print(1)
    exit()
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,0)]  #今の数 操作回数
ans = int(1e10)
# print(d)
while stack:
    now = stack.pop()
    # print(now)
    if now[0] > m:
        ans = min(ans,now[1])
        # print(now)
        continue
    if ceil(m+1,max(ac)) <= now[0]:
        ans = min(ans,now[1]+1)
        # print(now)
        continue
    for i,j in d:
        stack.append((now[0]*j, now[1]+i))
print(ans)





0