A14 - Four Boxes
https://atcoder.jp/contests/tessoku-book/tasks/tessoku_book_n
提出
TLE
code: python
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
d = list(map(int, input().split()))
# O(pow(1000, 4))
ab = []
cd = []
for va in a:
for vb in b:
ab.append(va + vb)
for vc in c:
for vd in d:
cd.append(vc + vd)
for vab in ab:
for vcd in cd:
if vab + vcd == k:
print("Yes")
exit()
print("No")
解答
code: python
import bisect
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
d = list(map(int, input().split()))
# O(pow(1000, 4))
ab = []
cd = []
for va in a:
for vb in b:
ab.append(va + vb)
for vc in c:
for vd in d:
cd.append(vc + vd)
cd.sort()
for i in range(len(ab)):
p = bisect.bisect_left(cd, k-abi)
if p < n*n and cdp == k-abi:
print("Yes")
exit(0)
print("No")
提出
code: python
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
d = list(map(int, input().split()))
# O(pow(1000, 2))
sumab = []
for i in range(n):
for j in range(n):
sumab.append(ai+bj)
sumcd = set()
for i in range(n):
for j in range(n):
sumcd.add(ci+dj)
# print(sumab)
# print(sumcd)
# 7, 10, 12, 13, 16, 18, 21, 24, 26 -> 1こ
# 11, 12, 13, 21, 22, 23, 31, 32, 33 -> 1こ
# pow(pow(1000, 2), 2) TLE
for i in range(n*n):
if k-sumabi in sumcd:
print("Yes")
exit()
print("No")