結果

問題 No.2542 Yokan for Two
ユーザー ShirotsumeShirotsume
提出日時 2023-07-23 01:23:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 422 ms / 2,000 ms
コード長 728 bytes
コンパイル時間 259 ms
コンパイル使用メモリ 82,448 KB
実行使用メモリ 135,204 KB
最終ジャッジ日時 2024-04-09 18:35:27
合計ジャッジ時間 9,900 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
55,692 KB
testcase_01 AC 45 ms
56,612 KB
testcase_02 AC 45 ms
57,080 KB
testcase_03 AC 169 ms
89,600 KB
testcase_04 AC 132 ms
82,620 KB
testcase_05 AC 248 ms
104,400 KB
testcase_06 AC 50 ms
62,976 KB
testcase_07 AC 396 ms
135,204 KB
testcase_08 AC 156 ms
85,832 KB
testcase_09 AC 422 ms
132,028 KB
testcase_10 AC 97 ms
74,512 KB
testcase_11 AC 110 ms
77,584 KB
testcase_12 AC 197 ms
96,512 KB
testcase_13 AC 91 ms
73,888 KB
testcase_14 AC 217 ms
99,832 KB
testcase_15 AC 264 ms
102,752 KB
testcase_16 AC 229 ms
101,960 KB
testcase_17 AC 231 ms
97,376 KB
testcase_18 AC 241 ms
103,796 KB
testcase_19 AC 146 ms
84,568 KB
testcase_20 AC 130 ms
80,480 KB
testcase_21 AC 141 ms
80,696 KB
testcase_22 AC 136 ms
82,860 KB
testcase_23 AC 149 ms
82,188 KB
testcase_24 AC 66 ms
67,452 KB
testcase_25 AC 90 ms
74,832 KB
testcase_26 AC 89 ms
73,320 KB
testcase_27 AC 90 ms
74,076 KB
testcase_28 AC 99 ms
76,396 KB
testcase_29 AC 156 ms
87,932 KB
testcase_30 AC 209 ms
96,660 KB
testcase_31 AC 223 ms
95,600 KB
testcase_32 AC 214 ms
94,480 KB
testcase_33 AC 210 ms
97,632 KB
testcase_34 AC 234 ms
101,476 KB
testcase_35 AC 265 ms
104,336 KB
testcase_36 AC 251 ms
101,784 KB
testcase_37 AC 272 ms
104,776 KB
testcase_38 AC 275 ms
107,384 KB
testcase_39 AC 295 ms
110,936 KB
testcase_40 AC 257 ms
107,432 KB
testcase_41 AC 263 ms
103,740 KB
testcase_42 AC 260 ms
102,172 KB
testcase_43 AC 243 ms
103,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, time, random
from collections import deque, Counter, defaultdict
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
inf = 2 ** 63 - 1
mod = 998244353

l, n = mi()

x = li()
x.append(l)
x.insert(0, 0)
a = []
for i in range(n + 1):
    a.append(x[i + 1] - x[i])

A = a[0]
B = a[-1]
a = a[1:-1]
l = sum(a)
dp = [[False] * (l + 1) for _ in range(n)]

dp[0][0] = True

for i in range(n - 1):
    for j in range(l + 1):
        dp[i + 1][j] |= dp[i][j]
        if j + a[i] <= l:
            dp[i + 1][j + a[i]] |= dp[i][j]
ans = inf

for i in range(l + 1):
    if dp[n - 1][i]:
        ans = min(ans, abs(A + i - B - (l - i)))
print(ans)
0