結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 241 ms
120,920 KB
testcase_02 AC 73 ms
71,368 KB
testcase_03 AC 75 ms
71,412 KB
testcase_04 AC 76 ms
71,316 KB
testcase_05 AC 77 ms
71,368 KB
testcase_06 AC 215 ms
107,392 KB
testcase_07 AC 234 ms
120,928 KB
testcase_08 AC 751 ms
126,280 KB
testcase_09 AC 760 ms
125,868 KB
testcase_10 AC 734 ms
126,120 KB
testcase_11 AC 744 ms
126,372 KB
testcase_12 AC 773 ms
126,476 KB
testcase_13 AC 74 ms
71,528 KB
testcase_14 AC 75 ms
71,176 KB
testcase_15 AC 74 ms
71,280 KB
testcase_16 AC 76 ms
71,328 KB
testcase_17 AC 76 ms
71,412 KB
testcase_18 AC 121 ms
102,836 KB
testcase_19 AC 119 ms
102,704 KB
testcase_20 AC 119 ms
102,980 KB
testcase_21 AC 118 ms
102,744 KB
testcase_22 AC 116 ms
102,796 KB
testcase_23 AC 220 ms
127,508 KB
testcase_24 AC 75 ms
71,208 KB
testcase_25 AC 75 ms
71,320 KB
testcase_26 AC 73 ms
71,240 KB
testcase_27 AC 74 ms
71,252 KB
testcase_28 AC 75 ms
71,196 KB
testcase_29 AC 74 ms
71,096 KB
testcase_30 AC 74 ms
71,372 KB
testcase_31 AC 73 ms
71,508 KB
testcase_32 AC 72 ms
71,464 KB
testcase_33 AC 74 ms
71,296 KB
testcase_34 AC 109 ms
95,828 KB
testcase_35 AC 86 ms
80,960 KB
testcase_36 AC 107 ms
98,312 KB
testcase_37 AC 103 ms
95,392 KB
testcase_38 AC 91 ms
87,100 KB
testcase_39 AC 85 ms
82,416 KB
testcase_40 AC 89 ms
84,600 KB
testcase_41 AC 83 ms
79,056 KB
testcase_42 AC 100 ms
93,132 KB
testcase_43 AC 105 ms
95,724 KB
testcase_44 AC 219 ms
107,404 KB
testcase_45 AC 218 ms
107,288 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)//max_A  # 目標値

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