結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 304 ms
76,868 KB
testcase_01 AC 38 ms
55,860 KB
testcase_02 AC 55 ms
66,804 KB
testcase_03 AC 37 ms
55,860 KB
testcase_04 AC 38 ms
55,860 KB
testcase_05 AC 57 ms
66,792 KB
testcase_06 AC 39 ms
55,860 KB
testcase_07 AC 37 ms
55,860 KB
testcase_08 AC 39 ms
55,860 KB
testcase_09 AC 38 ms
55,860 KB
testcase_10 AC 38 ms
55,860 KB
testcase_11 AC 37 ms
55,860 KB
testcase_12 AC 41 ms
59,828 KB
testcase_13 AC 226 ms
76,604 KB
testcase_14 AC 289 ms
76,868 KB
testcase_15 AC 230 ms
76,864 KB
testcase_16 AC 258 ms
76,612 KB
testcase_17 AC 50 ms
64,688 KB
testcase_18 AC 61 ms
66,796 KB
testcase_19 AC 54 ms
64,688 KB
testcase_20 AC 78 ms
70,960 KB
testcase_21 AC 45 ms
59,828 KB
testcase_22 AC 43 ms
55,860 KB
testcase_23 AC 47 ms
55,860 KB
testcase_24 AC 41 ms
55,860 KB
testcase_25 AC 42 ms
55,860 KB
testcase_26 AC 42 ms
55,860 KB
testcase_27 AC 52 ms
64,456 KB
testcase_28 AC 43 ms
55,860 KB
testcase_29 AC 43 ms
55,860 KB
testcase_30 AC 38 ms
55,860 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *
N,M,A,B=map(int,input().split())
C=sorted(list(map(int,input().split())))
inf=10**18
d=defaultdict(lambda:inf)
z=defaultdict(lambda:inf)
d[1]=0
D=set()
for i in range(1,int(N**0.5)+1):
 if N%i==0:D.add(i);D.add(N//i)
D=sorted(list(D))
K=len(D)
for i in range(K):
 v=D[i]
 for j in range(M):
  if C[j]%v==0:z[v]=min(z[v],C[j])
 y=inf
 for j in range(i):
  x=D[j]
  if v%x==0 and z[x]>v:
   y=min(y,d[x]+B*(i<K-1)+(v//x-1)*A)
  d[v]=y*(i!=0)
print(d[N] if d[N]!=inf else -1)
0