結果

問題 No.2039 Copy and Avoid
ユーザー hir355hir355
提出日時 2022-08-12 22:42:20
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 830 bytes
コンパイル時間 426 ms
コンパイル使用メモリ 81,832 KB
実行使用メモリ 66,572 KB
最終ジャッジ日時 2023-10-24 11:01:03
合計ジャッジ時間 3,658 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 158 ms
66,544 KB
testcase_01 AC 36 ms
53,500 KB
testcase_02 AC 43 ms
60,036 KB
testcase_03 AC 36 ms
53,500 KB
testcase_04 AC 36 ms
53,500 KB
testcase_05 AC 44 ms
62,084 KB
testcase_06 AC 36 ms
53,500 KB
testcase_07 AC 37 ms
53,500 KB
testcase_08 AC 36 ms
53,500 KB
testcase_09 AC 36 ms
53,500 KB
testcase_10 AC 39 ms
53,500 KB
testcase_11 AC 36 ms
53,500 KB
testcase_12 AC 39 ms
57,244 KB
testcase_13 AC 170 ms
66,568 KB
testcase_14 AC 168 ms
66,560 KB
testcase_15 AC 167 ms
66,572 KB
testcase_16 AC 158 ms
66,568 KB
testcase_17 WA -
testcase_18 AC 44 ms
62,084 KB
testcase_19 AC 42 ms
62,084 KB
testcase_20 WA -
testcase_21 AC 37 ms
53,500 KB
testcase_22 AC 38 ms
53,500 KB
testcase_23 AC 37 ms
53,500 KB
testcase_24 AC 36 ms
53,500 KB
testcase_25 AC 37 ms
53,500 KB
testcase_26 AC 37 ms
53,500 KB
testcase_27 AC 44 ms
59,824 KB
testcase_28 AC 37 ms
53,500 KB
testcase_29 AC 36 ms
53,500 KB
testcase_30 AC 36 ms
53,500 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 ** 10:
    print(-1)
else:
    print(dp[-1] - b)
0