結果

問題 No.1330 Multiply or Divide
ユーザー ayaoniayaoni
提出日時 2021-01-14 02:53:24
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,297 bytes
コンパイル時間 477 ms
コンパイル使用メモリ 87,200 KB
実行使用メモリ 127,516 KB
最終ジャッジ日時 2023-08-15 00:06:25
合計ジャッジ時間 11,365 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 261 ms
120,880 KB
testcase_02 AC 78 ms
71,128 KB
testcase_03 AC 76 ms
71,348 KB
testcase_04 AC 77 ms
71,016 KB
testcase_05 AC 77 ms
71,176 KB
testcase_06 AC 225 ms
107,292 KB
testcase_07 AC 246 ms
120,648 KB
testcase_08 AC 825 ms
126,084 KB
testcase_09 AC 829 ms
125,720 KB
testcase_10 AC 834 ms
126,092 KB
testcase_11 AC 816 ms
126,128 KB
testcase_12 AC 818 ms
126,304 KB
testcase_13 AC 75 ms
71,136 KB
testcase_14 AC 75 ms
71,284 KB
testcase_15 AC 76 ms
71,172 KB
testcase_16 AC 77 ms
71,312 KB
testcase_17 AC 76 ms
71,232 KB
testcase_18 AC 121 ms
102,684 KB
testcase_19 AC 121 ms
102,772 KB
testcase_20 AC 120 ms
102,600 KB
testcase_21 AC 121 ms
102,680 KB
testcase_22 AC 122 ms
102,460 KB
testcase_23 AC 235 ms
127,516 KB
testcase_24 AC 77 ms
71,348 KB
testcase_25 AC 76 ms
71,320 KB
testcase_26 AC 75 ms
71,348 KB
testcase_27 AC 76 ms
71,172 KB
testcase_28 AC 75 ms
71,160 KB
testcase_29 AC 76 ms
71,348 KB
testcase_30 AC 75 ms
71,304 KB
testcase_31 AC 75 ms
71,380 KB
testcase_32 AC 75 ms
71,256 KB
testcase_33 AC 76 ms
71,176 KB
testcase_34 AC 114 ms
95,672 KB
testcase_35 AC 85 ms
81,060 KB
testcase_36 AC 109 ms
98,172 KB
testcase_37 AC 104 ms
95,344 KB
testcase_38 AC 96 ms
86,932 KB
testcase_39 AC 90 ms
81,980 KB
testcase_40 AC 90 ms
84,484 KB
testcase_41 AC 85 ms
78,592 KB
testcase_42 AC 99 ms
92,768 KB
testcase_43 AC 105 ms
95,408 KB
testcase_44 AC 214 ms
107,104 KB
testcase_45 AC 205 ms
107,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from operator import itemgetter
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())


N,M,P = MI()
A = LI()

max_A = max(A)
# 最後の1回の操作はmax_Aを掛ける
X = M//max_A+1  # 目標値

if X == 1:
    print(1)
    exit()

B = []
for a in A:
    r = 0
    while a % P == 0:
        r += 1
        a //= P
    B.append((r+1,-a))  # (操作回数,-(結局何倍になるか))

B = sorted(B,key=itemgetter(0,1))
C = []
r,a = B[0]
a *= -1
C.append((r,a))

for i in range(1,N):
    r,a = B[i]
    a *= -1
    if B[-1][0] < r and B[-1][1] < a:
        C.append((r,a))

for r,a in C:
    if a != 1:
        break
else:
    print(-1)
    exit()

dp = [1]*10000  # dp[i] = i回の操作でできる最大値
for i in range(1,10000):
    for r,a in C:
        if i >= r:
            dp[i] = max(dp[i],dp[i-r]*a)
    if dp[i] >= X:
        print(i+1)  # 最後の1回の操作を追加
        break
0