結果

問題 No.1330 Multiply or Divide
ユーザー ayaoniayaoni
提出日時 2021-01-14 02:56:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 871 ms / 2,000 ms
コード長 1,297 bytes
コンパイル時間 276 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 121,284 KB
最終ジャッジ日時 2024-05-02 12:20:46
合計ジャッジ時間 9,725 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
52,956 KB
testcase_01 AC 231 ms
107,136 KB
testcase_02 AC 42 ms
52,952 KB
testcase_03 AC 41 ms
54,132 KB
testcase_04 AC 41 ms
53,708 KB
testcase_05 AC 40 ms
53,084 KB
testcase_06 AC 207 ms
116,544 KB
testcase_07 AC 225 ms
107,440 KB
testcase_08 AC 861 ms
120,716 KB
testcase_09 AC 870 ms
120,844 KB
testcase_10 AC 871 ms
120,724 KB
testcase_11 AC 861 ms
121,216 KB
testcase_12 AC 858 ms
120,716 KB
testcase_13 AC 42 ms
52,764 KB
testcase_14 AC 42 ms
53,220 KB
testcase_15 AC 41 ms
52,616 KB
testcase_16 AC 42 ms
53,088 KB
testcase_17 AC 41 ms
52,948 KB
testcase_18 AC 104 ms
102,116 KB
testcase_19 AC 104 ms
101,748 KB
testcase_20 AC 102 ms
101,728 KB
testcase_21 AC 102 ms
101,728 KB
testcase_22 AC 97 ms
102,200 KB
testcase_23 AC 221 ms
121,284 KB
testcase_24 AC 41 ms
53,164 KB
testcase_25 AC 42 ms
53,148 KB
testcase_26 AC 42 ms
54,088 KB
testcase_27 AC 42 ms
53,976 KB
testcase_28 AC 41 ms
53,056 KB
testcase_29 AC 42 ms
54,184 KB
testcase_30 AC 41 ms
52,880 KB
testcase_31 AC 41 ms
53,560 KB
testcase_32 AC 42 ms
52,968 KB
testcase_33 AC 42 ms
53,992 KB
testcase_34 AC 81 ms
96,376 KB
testcase_35 AC 53 ms
68,724 KB
testcase_36 AC 78 ms
92,416 KB
testcase_37 AC 74 ms
88,448 KB
testcase_38 AC 62 ms
77,056 KB
testcase_39 AC 57 ms
70,912 KB
testcase_40 AC 59 ms
73,600 KB
testcase_41 AC 53 ms
65,664 KB
testcase_42 AC 70 ms
85,660 KB
testcase_43 AC 77 ms
89,800 KB
testcase_44 AC 205 ms
116,456 KB
testcase_45 AC 204 ms
116,136 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 C[-1][0] < r and C[-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