def test_all(f):
for i, data in enumerate(eval(f'test_data{f.__name__[0]}')):
exp = data["out"]
ans = f(*data["in"])
result = "AC" if exp == ans else "WA"
print(f"{i+1} {result}: expected: {exp}, output: {ans}")
def D(N, x, y, A):
SIZE = 10_000
x = x - A[0]
xs = []
ys = []
for i, a in enumerate(A[1:]):
if i % 2: xs.append(a)
else: ys.append(a)
def search(seed, target):
# print(seed, target)
dp = [False] * (2 * SIZE + 1)
dp[seed[0] + SIZE] = True
dp[-seed[0] + SIZE] = True
for s in seed[1:]:
new = dp.copy()
for i, b in enumerate(dp):
if b:
new[i + s] = True
new[i - s] = True
# print("2:", *[i - SIZE for i, b in enumerate(new) if b])
dp = new
# print(*[i - SIZE for i, b in enumerate(dp) if b])
return dp[target + SIZE]
return "Yes" if search(xs, x) and search(ys, y) else "No"test_all(D)
def D(N, x, y, A):
SIZE = 10_000
x = x - A[0]
xs = []
ys = []
for i, a in enumerate(A[1:]):
if i % 2: xs.append(a)
else: ys.append(a)
def search(seed, target):
# print(seed, target)
dp = [False] * (2 * SIZE + 1)
dp[seed[0] + SIZE] = True
dp[-seed[0] + SIZE] = True
for s in seed[1:]:
new = [False] * (2 * SIZE + 1)
for i, b in enumerate(dp):
if b:
new[i + s] = True
new[i - s] = True
# print("2:", *[i - SIZE for i, b in enumerate(new) if b])
dp = new
# print(*[i - SIZE for i, b in enumerate(dp) if b])
return dp[target + SIZE]
return "Yes" if search(xs, x) and search(ys, y) else "No"test_all(D)