結果

問題 No.1330 Multiply or Divide
ユーザー U SU S
提出日時 2021-01-08 21:49:36
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,056 bytes
コンパイル時間 151 ms
コンパイル使用メモリ 81,984 KB
実行使用メモリ 117,828 KB
最終ジャッジ日時 2024-04-28 02:42:20
合計ジャッジ時間 6,648 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 169 ms
112,048 KB
testcase_02 WA -
testcase_03 AC 47 ms
60,416 KB
testcase_04 AC 48 ms
60,672 KB
testcase_05 AC 50 ms
60,672 KB
testcase_06 AC 90 ms
101,888 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 AC 173 ms
116,920 KB
testcase_19 AC 170 ms
117,060 KB
testcase_20 AC 168 ms
116,812 KB
testcase_21 AC 168 ms
116,984 KB
testcase_22 AC 169 ms
116,932 KB
testcase_23 WA -
testcase_24 RE -
testcase_25 AC 51 ms
60,672 KB
testcase_26 RE -
testcase_27 AC 51 ms
60,672 KB
testcase_28 AC 51 ms
60,672 KB
testcase_29 AC 51 ms
60,800 KB
testcase_30 AC 50 ms
60,416 KB
testcase_31 RE -
testcase_32 RE -
testcase_33 AC 50 ms
60,288 KB
testcase_34 AC 144 ms
104,864 KB
testcase_35 AC 77 ms
78,848 KB
testcase_36 AC 131 ms
98,336 KB
testcase_37 AC 121 ms
96,000 KB
testcase_38 AC 95 ms
90,368 KB
testcase_39 AC 82 ms
81,024 KB
testcase_40 AC 94 ms
85,312 KB
testcase_41 AC 79 ms
74,752 KB
testcase_42 AC 132 ms
93,824 KB
testcase_43 AC 132 ms
96,324 KB
testcase_44 RE -
testcase_45 RE -
権限があれば一括ダウンロードができます

ソースコード

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





0