結果

問題 No.1330 Multiply or Divide
ユーザー tamatotamato
提出日時 2021-01-08 21:57:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 226 ms / 2,000 ms
コード長 879 bytes
コンパイル時間 2,733 ms
コンパイル使用メモリ 86,916 KB
実行使用メモリ 107,000 KB
最終ジャッジ日時 2023-08-10 13:05:55
合計ジャッジ時間 7,796 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 105 ms
77,688 KB
testcase_01 AC 152 ms
107,000 KB
testcase_02 AC 73 ms
71,600 KB
testcase_03 AC 94 ms
77,456 KB
testcase_04 AC 76 ms
76,024 KB
testcase_05 AC 99 ms
77,972 KB
testcase_06 AC 122 ms
104,164 KB
testcase_07 AC 226 ms
106,708 KB
testcase_08 AC 185 ms
102,888 KB
testcase_09 AC 199 ms
103,088 KB
testcase_10 AC 195 ms
103,012 KB
testcase_11 AC 190 ms
103,076 KB
testcase_12 AC 196 ms
102,976 KB
testcase_13 AC 123 ms
78,560 KB
testcase_14 AC 106 ms
77,960 KB
testcase_15 AC 106 ms
77,980 KB
testcase_16 AC 120 ms
78,748 KB
testcase_17 AC 104 ms
78,024 KB
testcase_18 AC 118 ms
99,864 KB
testcase_19 AC 117 ms
99,968 KB
testcase_20 AC 117 ms
99,956 KB
testcase_21 AC 116 ms
100,024 KB
testcase_22 AC 118 ms
99,776 KB
testcase_23 AC 174 ms
104,508 KB
testcase_24 AC 74 ms
71,484 KB
testcase_25 AC 73 ms
71,756 KB
testcase_26 AC 93 ms
77,552 KB
testcase_27 AC 68 ms
71,796 KB
testcase_28 AC 69 ms
71,740 KB
testcase_29 AC 70 ms
71,348 KB
testcase_30 AC 69 ms
71,720 KB
testcase_31 AC 70 ms
71,344 KB
testcase_32 AC 73 ms
71,864 KB
testcase_33 AC 97 ms
77,924 KB
testcase_34 AC 107 ms
99,816 KB
testcase_35 AC 85 ms
80,788 KB
testcase_36 AC 101 ms
97,132 KB
testcase_37 AC 98 ms
94,228 KB
testcase_38 AC 90 ms
86,584 KB
testcase_39 AC 83 ms
81,848 KB
testcase_40 AC 88 ms
83,900 KB
testcase_41 AC 80 ms
78,624 KB
testcase_42 AC 96 ms
92,292 KB
testcase_43 AC 101 ms
94,732 KB
testcase_44 AC 142 ms
105,396 KB
testcase_45 AC 137 ms
105,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9
inf = 10**17


def main():
    import sys
    input = sys.stdin.readline

    N, M, P = map(int, input().split())
    A = list(map(int, input().split()))

    if max(A) > M:
        print(1)
        exit()

    B = [1] * 40
    for a in A:
        cnt = 0
        aa = a
        while aa % P == 0:
            cnt += 1
            aa //= P
        B[cnt] = max(B[cnt], aa)

    dp = [[-inf] * 1000 for _ in range(40)]
    dp[0][0] = 1
    ans = inf
    ma = max(A)
    for i in range(40):
        for j in range(1000):
            if i != 0:
                dp[i][j] = dp[i-1][j]
            if j - i - 1 >= 0:
                dp[i][j] = max(dp[i][j], dp[i][j-i-1] * B[i])
            if dp[i][j] * ma > M:
                ans = min(ans, j+1)
    if ans != inf:
        print(ans)
    else:
        print(-1)


if __name__ == '__main__':
    main()
0