結果

問題 No.2542 Yokan for Two
ユーザー flygonflygon
提出日時 2023-11-24 21:44:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,142 ms / 2,000 ms
コード長 1,006 bytes
コンパイル時間 139 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 260,648 KB
最終ジャッジ日時 2023-11-24 21:45:22
合計ジャッジ時間 27,830 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
55,720 KB
testcase_01 AC 43 ms
55,720 KB
testcase_02 AC 42 ms
55,720 KB
testcase_03 AC 418 ms
160,704 KB
testcase_04 AC 226 ms
96,144 KB
testcase_05 AC 497 ms
188,316 KB
testcase_06 AC 90 ms
82,716 KB
testcase_07 AC 821 ms
257,560 KB
testcase_08 AC 335 ms
131,388 KB
testcase_09 AC 889 ms
258,708 KB
testcase_10 AC 160 ms
90,896 KB
testcase_11 AC 183 ms
92,224 KB
testcase_12 AC 465 ms
158,648 KB
testcase_13 AC 149 ms
88,844 KB
testcase_14 AC 866 ms
259,196 KB
testcase_15 AC 895 ms
258,948 KB
testcase_16 AC 882 ms
257,280 KB
testcase_17 AC 848 ms
258,696 KB
testcase_18 AC 1,033 ms
259,280 KB
testcase_19 AC 534 ms
156,436 KB
testcase_20 AC 492 ms
146,936 KB
testcase_21 AC 492 ms
147,072 KB
testcase_22 AC 530 ms
149,384 KB
testcase_23 AC 518 ms
151,624 KB
testcase_24 AC 135 ms
101,316 KB
testcase_25 AC 171 ms
113,668 KB
testcase_26 AC 173 ms
113,576 KB
testcase_27 AC 186 ms
113,692 KB
testcase_28 AC 196 ms
116,720 KB
testcase_29 AC 358 ms
148,152 KB
testcase_30 AC 932 ms
260,348 KB
testcase_31 AC 933 ms
257,468 KB
testcase_32 AC 1,020 ms
260,344 KB
testcase_33 AC 914 ms
260,508 KB
testcase_34 AC 921 ms
260,512 KB
testcase_35 AC 1,142 ms
257,444 KB
testcase_36 AC 1,132 ms
257,368 KB
testcase_37 AC 923 ms
260,512 KB
testcase_38 AC 918 ms
260,520 KB
testcase_39 AC 906 ms
260,596 KB
testcase_40 AC 932 ms
257,468 KB
testcase_41 AC 932 ms
257,540 KB
testcase_42 AC 914 ms
257,540 KB
testcase_43 AC 932 ms
260,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(5*10**5)
input = sys.stdin.readline
from collections import defaultdict, deque, Counter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right
from math import gcd

l,n = map(int,input().split())
x =[0] + list(map(int,input().split()))
x.append(l)
INF = 10**15
dp = [0]*((l*2+50)*2)
c = l+10
dp[c*2+1] = 1
for i in range(1,n+2):
    new = [0]*((l*2+50)*2)
    xi = x[i] - x[i-1]
    for j in range(l*2+50):
        for k in range(2):
            if k == 0:
                if j + xi < l*2+50:
                    new[(j+xi)*2+k] |= dp[j*2+k]
                if j -xi >= 0:
                    new[(j-xi)*2+(k^1)] |= dp[j*2+k]
            else:
                if j - xi >= 0 and i != 1:
                    new[(j-xi)*2+k] |= dp[j*2+k]
                if j + xi < l*2+50:
                    new[(j+xi)*2+(k^1)] |= dp[j*2+k]
    dp = new
    # print(dp)
mn = INF
for i in range(2*l+50):
    if dp[i*2+1]:
        mn = min(mn, abs(i-c))

print(mn)
0