結果

問題 No.2542 Yokan for Two
ユーザー flygonflygon
提出日時 2023-11-24 21:42:15
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,014 bytes
コンパイル時間 434 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 395,760 KB
最終ジャッジ日時 2023-11-24 21:42:24
合計ジャッジ時間 8,246 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
62,528 KB
testcase_01 AC 43 ms
55,724 KB
testcase_02 AC 42 ms
55,724 KB
testcase_03 AC 1,321 ms
376,956 KB
testcase_04 AC 573 ms
254,776 KB
testcase_05 AC 1,791 ms
312,240 KB
testcase_06 AC 137 ms
105,092 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます

ソースコード

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]*2 for i in range(l*2+50)] 
c = l+10
dp[c][1] = 1
for i in range(1,n+2):
    new = [[0]*2 for i in range(l*2+50)] 
    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][k] |= dp[j][k]
                if j -xi >= 0:
                    new[j-xi][k^1] |= dp[j][k]
            else:
                if j - xi >= 0 and i != 1:
                    new[j-xi][k] |= dp[j][k]
                if j + xi < l*2+50:
                    new[j+xi][k^1] |= dp[j][k]
    dp = new
    # print(dp)
mn = INF
for i in range(2*l+50):
    if dp[i][1]:
        mn = min(mn, abs(i-c))

print(mn)
0