結果

問題 No.2039 Copy and Avoid
ユーザー taiga0629kyoprotaiga0629kyopro
提出日時 2022-08-12 22:56:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 312 ms / 2,000 ms
コード長 1,534 bytes
コンパイル時間 168 ms
コンパイル使用メモリ 81,780 KB
実行使用メモリ 76,996 KB
最終ジャッジ日時 2023-10-24 11:15:59
合計ジャッジ時間 4,210 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 312 ms
76,760 KB
testcase_01 AC 37 ms
53,544 KB
testcase_02 AC 56 ms
68,572 KB
testcase_03 AC 36 ms
53,544 KB
testcase_04 AC 36 ms
53,544 KB
testcase_05 AC 54 ms
66,516 KB
testcase_06 AC 36 ms
53,544 KB
testcase_07 AC 36 ms
53,544 KB
testcase_08 AC 37 ms
53,544 KB
testcase_09 AC 35 ms
53,544 KB
testcase_10 AC 36 ms
53,544 KB
testcase_11 AC 36 ms
53,544 KB
testcase_12 AC 40 ms
59,844 KB
testcase_13 AC 301 ms
76,996 KB
testcase_14 AC 297 ms
76,584 KB
testcase_15 AC 298 ms
76,824 KB
testcase_16 AC 285 ms
76,676 KB
testcase_17 AC 45 ms
62,384 KB
testcase_18 AC 52 ms
66,500 KB
testcase_19 AC 45 ms
62,392 KB
testcase_20 AC 77 ms
72,904 KB
testcase_21 AC 46 ms
62,208 KB
testcase_22 AC 38 ms
53,544 KB
testcase_23 AC 36 ms
53,544 KB
testcase_24 AC 36 ms
53,544 KB
testcase_25 AC 36 ms
53,544 KB
testcase_26 AC 36 ms
53,544 KB
testcase_27 AC 48 ms
62,288 KB
testcase_28 AC 36 ms
53,544 KB
testcase_29 AC 36 ms
53,544 KB
testcase_30 AC 36 ms
53,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #





####二分探索###################################

#配列は昇順にソートずみ
def bilower(a,x):
    # a[i]<=x となる最大のiを返す ない時は-1
    if len(a)==0:return -1
    mi=0
    ma=len(a)-1
    if a[0]>x:return -1
    if a[ma]<=x:return ma
    while ma-mi>1:
        mid=(ma+mi)//2
        if a[mid]<=x:mi=mid
        else:ma=mid
    return mi

def bihigher(a,x):
    # a[i]>=x となる最小のiを返す ない時は len(a)
    if len(a)==0:return 0
    mi=0
    ma=len(a)-1
    if a[ma]<x:return ma+1
    if a[0]>=x:return 0
    while ma-mi>1:
        mid=(ma+mi)//2
        if a[mid]>=x:ma=mid
        else:mi=mid
    return ma

def birange(a,l,r):
    if l>=r:return 0
    r-=1
    #l<=a[i]<r となるiの個数を返す
    left=bihigher(a,l)
    right=bilower(a,r)
    return right-left+1

################################################


n,m,a,b=map(int,input().split())
c=list(map(int,input().split()))
from _collections import defaultdict
yaku=set()
for i in range(1,n+1):
    if i**2>n:break
    if n%i==0:
        yaku.add(i)
        yaku.add(n//i)
yaku=list(yaku)
yaku.sort()
ng=defaultdict(lambda:[])
for x in yaku:
    for y in c:
        if y%x==0:
            ng[x].append(y)
    ng[x].sort()

dp=defaultdict(lambda:2**63)
dp[1]=0
for x in yaku:
    if x==1:continue
    for y in yaku:
        if x%y!=0:continue
        if birange(ng[y],1,x+1)>0:continue
        cnt=1
        if y==1:cnt=0
        dp[x]=min(dp[x],dp[y]+a*(x-y)//y+b*cnt)
ans=dp[n]
if ans>10**18:ans=-1
print(ans)
0