結果

問題 No.2039 Copy and Avoid
ユーザー hir355hir355
提出日時 2022-08-12 22:43:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 164 ms / 2,000 ms
コード長 830 bytes
コンパイル時間 529 ms
コンパイル使用メモリ 81,768 KB
実行使用メモリ 66,596 KB
最終ジャッジ日時 2023-10-24 11:03:06
合計ジャッジ時間 3,191 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 159 ms
66,568 KB
testcase_01 AC 36 ms
53,524 KB
testcase_02 AC 41 ms
60,060 KB
testcase_03 AC 34 ms
53,524 KB
testcase_04 AC 38 ms
53,524 KB
testcase_05 AC 43 ms
62,108 KB
testcase_06 AC 40 ms
53,524 KB
testcase_07 AC 35 ms
53,524 KB
testcase_08 AC 34 ms
53,524 KB
testcase_09 AC 37 ms
53,524 KB
testcase_10 AC 38 ms
53,524 KB
testcase_11 AC 35 ms
53,524 KB
testcase_12 AC 42 ms
57,268 KB
testcase_13 AC 164 ms
66,592 KB
testcase_14 AC 162 ms
66,584 KB
testcase_15 AC 159 ms
66,596 KB
testcase_16 AC 153 ms
66,592 KB
testcase_17 AC 42 ms
62,108 KB
testcase_18 AC 43 ms
62,108 KB
testcase_19 AC 42 ms
62,108 KB
testcase_20 AC 50 ms
62,264 KB
testcase_21 AC 39 ms
53,524 KB
testcase_22 AC 35 ms
53,524 KB
testcase_23 AC 35 ms
53,524 KB
testcase_24 AC 35 ms
53,524 KB
testcase_25 AC 36 ms
53,524 KB
testcase_26 AC 35 ms
53,524 KB
testcase_27 AC 42 ms
59,848 KB
testcase_28 AC 36 ms
53,524 KB
testcase_29 AC 35 ms
53,524 KB
testcase_30 AC 35 ms
53,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def devisors(n):
    d = []
    a = 1
    while a * a < n:
        if n % a == 0:
            d.append(a)
            d.append(n // a)
        a += 1
    if a * a == n:
        d.append(a)
    return d

INF = 10 ** 18
n, m, a, b = map(int, input().split())
c = list(map(int, input().split()))
c.sort()
dv = devisors(n)
dv.sort()
k = len(dv)
dp = [INF] * k
dp[0] = 0
prv = [-1] * k
for i in range(k):
    x = INF
    for j in range(m):
        if c[j] % dv[i] == 0:
            x = c[j]
            break
    for j in range(i + 1, k):
        if dv[j] % dv[i] > 0:
            continue
        if dv[j] >= x:
            break
        if dp[j] > dp[i] + a * (dv[j] // dv[i] - 1) + b:
            dp[j] = dp[i] + a * (dv[j] // dv[i] - 1) + b
            prv[j] = dv[i]
if dp[-1] > 10 ** 15:
    print(-1)
else:
    print(dp[-1] - b)
0