結果

問題 No.1330 Multiply or Divide
ユーザー U SU S
提出日時 2021-01-08 22:10:46
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,121 bytes
コンパイル時間 157 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 117,600 KB
最終ジャッジ日時 2024-04-28 03:22:49
合計ジャッジ時間 5,866 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 151 ms
111,664 KB
testcase_02 WA -
testcase_03 AC 44 ms
60,288 KB
testcase_04 AC 45 ms
60,544 KB
testcase_05 AC 44 ms
60,160 KB
testcase_06 AC 84 ms
101,504 KB
testcase_07 WA -
testcase_08 AC 149 ms
116,944 KB
testcase_09 AC 154 ms
117,200 KB
testcase_10 AC 156 ms
116,948 KB
testcase_11 AC 148 ms
117,076 KB
testcase_12 AC 152 ms
117,084 KB
testcase_13 AC 128 ms
76,416 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 98 ms
76,544 KB
testcase_17 WA -
testcase_18 AC 153 ms
117,080 KB
testcase_19 AC 152 ms
116,948 KB
testcase_20 AC 154 ms
116,948 KB
testcase_21 AC 151 ms
116,944 KB
testcase_22 AC 152 ms
117,080 KB
testcase_23 WA -
testcase_24 AC 44 ms
60,160 KB
testcase_25 AC 43 ms
60,416 KB
testcase_26 WA -
testcase_27 AC 45 ms
60,160 KB
testcase_28 AC 45 ms
60,800 KB
testcase_29 AC 44 ms
60,416 KB
testcase_30 AC 45 ms
60,288 KB
testcase_31 AC 45 ms
60,800 KB
testcase_32 AC 44 ms
60,160 KB
testcase_33 AC 46 ms
60,672 KB
testcase_34 AC 134 ms
105,040 KB
testcase_35 AC 73 ms
78,720 KB
testcase_36 AC 121 ms
98,432 KB
testcase_37 AC 115 ms
95,872 KB
testcase_38 AC 94 ms
90,240 KB
testcase_39 AC 77 ms
81,152 KB
testcase_40 AC 84 ms
85,248 KB
testcase_41 AC 68 ms
74,752 KB
testcase_42 AC 107 ms
93,824 KB
testcase_43 AC 113 ms
96,000 KB
testcase_44 WA -
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 == 1:
    print(0)
    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)
    else:
        for i,j in d:
            stack.append((now[0]*j, now[1]+i))
print(ans)





0