結果

問題 No.1330 Multiply or Divide
ユーザー U SU S
提出日時 2021-01-08 22:37:21
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,251 bytes
コンパイル時間 190 ms
コンパイル使用メモリ 82,244 KB
実行使用メモリ 117,412 KB
最終ジャッジ日時 2024-04-28 04:04:18
合計ジャッジ時間 6,174 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 177 ms
112,048 KB
testcase_02 AC 52 ms
60,544 KB
testcase_03 AC 51 ms
60,544 KB
testcase_04 AC 54 ms
60,288 KB
testcase_05 AC 53 ms
60,544 KB
testcase_06 AC 95 ms
102,016 KB
testcase_07 WA -
testcase_08 AC 177 ms
116,804 KB
testcase_09 AC 183 ms
116,908 KB
testcase_10 AC 173 ms
116,844 KB
testcase_11 AC 171 ms
117,172 KB
testcase_12 AC 173 ms
117,012 KB
testcase_13 AC 52 ms
61,056 KB
testcase_14 AC 52 ms
61,440 KB
testcase_15 AC 52 ms
60,928 KB
testcase_16 AC 54 ms
61,312 KB
testcase_17 AC 50 ms
60,672 KB
testcase_18 AC 110 ms
102,960 KB
testcase_19 AC 103 ms
102,460 KB
testcase_20 AC 106 ms
102,532 KB
testcase_21 AC 106 ms
102,460 KB
testcase_22 AC 105 ms
102,320 KB
testcase_23 AC 140 ms
117,412 KB
testcase_24 AC 52 ms
60,416 KB
testcase_25 AC 52 ms
60,416 KB
testcase_26 AC 52 ms
60,672 KB
testcase_27 AC 54 ms
60,672 KB
testcase_28 AC 56 ms
60,160 KB
testcase_29 AC 53 ms
60,288 KB
testcase_30 AC 52 ms
60,416 KB
testcase_31 AC 54 ms
60,416 KB
testcase_32 AC 50 ms
60,416 KB
testcase_33 AC 50 ms
60,672 KB
testcase_34 AC 95 ms
96,256 KB
testcase_35 AC 61 ms
71,808 KB
testcase_36 AC 87 ms
95,232 KB
testcase_37 AC 81 ms
91,776 KB
testcase_38 AC 68 ms
80,868 KB
testcase_39 AC 66 ms
74,104 KB
testcase_40 AC 69 ms
76,524 KB
testcase_41 AC 59 ms
69,444 KB
testcase_42 AC 79 ms
88,708 KB
testcase_43 AC 80 ms
93,176 KB
testcase_44 AC 124 ms
104,788 KB
testcase_45 WA -
権限があれば一括ダウンロードができます

ソースコード

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 < 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()
    if now[0] > m:
        ans = min(ans,now[1])
        #print(now)
    elif now[0] >= ceil(m+1,max(a)):
        ans = min(ans,now[1]+1)
    else:
        for i,j in d:
            stack.append((now[0]*j, now[1]+i))
print(ans)





0