結果

問題 No.2039 Copy and Avoid
ユーザー rlangevinrlangevin
提出日時 2023-11-10 12:19:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 297 ms / 2,000 ms
コード長 773 bytes
コンパイル時間 234 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 73,664 KB
最終ジャッジ日時 2023-11-10 12:19:40
合計ジャッジ時間 5,010 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 258 ms
72,904 KB
testcase_01 AC 38 ms
55,608 KB
testcase_02 AC 53 ms
64,436 KB
testcase_03 AC 38 ms
55,608 KB
testcase_04 AC 38 ms
55,608 KB
testcase_05 AC 53 ms
66,532 KB
testcase_06 AC 38 ms
55,608 KB
testcase_07 AC 39 ms
55,608 KB
testcase_08 AC 38 ms
55,608 KB
testcase_09 AC 38 ms
55,608 KB
testcase_10 AC 60 ms
55,608 KB
testcase_11 AC 38 ms
55,608 KB
testcase_12 AC 43 ms
59,320 KB
testcase_13 AC 262 ms
73,144 KB
testcase_14 AC 257 ms
73,664 KB
testcase_15 AC 275 ms
73,408 KB
testcase_16 AC 297 ms
73,664 KB
testcase_17 AC 49 ms
64,432 KB
testcase_18 AC 57 ms
66,532 KB
testcase_19 AC 50 ms
64,432 KB
testcase_20 AC 69 ms
68,612 KB
testcase_21 AC 43 ms
59,576 KB
testcase_22 AC 39 ms
55,608 KB
testcase_23 AC 39 ms
55,608 KB
testcase_24 AC 38 ms
55,608 KB
testcase_25 AC 38 ms
55,608 KB
testcase_26 AC 39 ms
55,608 KB
testcase_27 AC 47 ms
62,224 KB
testcase_28 AC 38 ms
55,608 KB
testcase_29 AC 38 ms
55,608 KB
testcase_30 AC 39 ms
55,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *

def div(n):
    i = 1
    SS = set()
    while i * i <= n:
        if n % i == 0:
            SS.add(i)
            SS.add(n//i)
        i += 1
    return sorted(list(SS))    

N, M, A, B = map(int, input().split())
C = sorted(list(map(int, input().split())))
inf = 10 ** 18
dic = defaultdict(lambda : inf)
minv = defaultdict(lambda : inf)
dic[1] = 0
D = div(N)
K = len(D)
for i in range(K):
    for j in range(M):
        if C[j] % D[i] == 0:
            minv[D[i]] = min(minv[D[i]], C[j])

for i in range(1, K):
    val = inf
    for j in range(i):
        if D[i] % D[j] == 0 and minv[D[j]] > D[i]:
            val = min(val, dic[D[j]] + B * int(i<K-1) + (D[i]//D[j] - 1) * A)
    dic[D[i]] = val

print(dic[N]) if dic[N] != inf else print(-1)
0