結果

問題 No.2039 Copy and Avoid
ユーザー sotanishysotanishy
提出日時 2022-08-12 22:35:28
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 997 bytes
コンパイル時間 1,055 ms
コンパイル使用メモリ 81,624 KB
実行使用メモリ 82,352 KB
最終ジャッジ日時 2023-10-24 10:52:22
合計ジャッジ時間 5,108 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 40 ms
53,424 KB
testcase_02 AC 48 ms
62,004 KB
testcase_03 AC 41 ms
53,424 KB
testcase_04 WA -
testcase_05 AC 47 ms
62,004 KB
testcase_06 AC 39 ms
53,424 KB
testcase_07 AC 40 ms
53,424 KB
testcase_08 AC 39 ms
53,424 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 40 ms
53,424 KB
testcase_12 AC 43 ms
59,216 KB
testcase_13 AC 359 ms
81,340 KB
testcase_14 AC 362 ms
82,352 KB
testcase_15 AC 337 ms
81,388 KB
testcase_16 AC 342 ms
81,536 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 45 ms
62,004 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 39 ms
53,424 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 86 ms
76,052 KB
testcase_28 AC 39 ms
53,424 KB
testcase_29 AC 39 ms
53,424 KB
testcase_30 AC 39 ms
53,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush, heappop
import sys
input = sys.stdin.readline

def divisor(n):
    divisors = []
    i = 1
    while i * i < n:
        if n % i == 0:
            divisors.append(i)
            divisors.append(n // i)
        i += 1
    if i * i == n:
        divisors.append(i)
    divisors.sort()
    return divisors

N, M, A, B = map(int, input().split())
C = list(map(int, input().split()))
C.sort()
div = divisor(N)
leastmultiple = {}
for d in div:
    for c in C:
        if c % d == 0:
            leastmultiple[d] = c
            break

dist = {}
heap = [(0, N)]
dist[N] = 0
while heap:
    d, n = heappop(heap)
    if n == 1:
        print(d-B)
        exit()
    if dist[n] < d:
        continue
    for m in div:
        if m >= n:
            break
        if m in leastmultiple and leastmultiple[m] < n:
            continue
        nd = d + (n//m-1) * A + B
        if m not in dist or nd < dist[m]:
            dist[m] = nd
            heappush(heap, (nd, m))
print(-1)
0