s_id
stringlengths
10
10
p_id
stringlengths
6
6
u_id
stringlengths
10
10
date
stringlengths
10
10
language
stringclasses
1 value
original_language
stringclasses
11 values
filename_ext
stringclasses
1 value
status
stringclasses
1 value
cpu_time
stringlengths
1
5
memory
stringlengths
1
7
code_size
stringlengths
1
6
code
stringlengths
1
539k
s621667732
p02271
u796784914
1497085973
Python
Python
py
Runtime Error
0
0
922
class MyClass(): def main(self): self.n = input() self.A = map(int,raw_input().split()) self.q = input() self.M = map(int,raw_input().split()) W = map(self.solve,self.M) for w in W: print w def solve(self,m): w = self.rec(m,self.A) if w: return "yes" else: return "no" def rec(self,m,A): if len(A) == 1: r1 = False else: r1 = self.rec(m,A[1:]) m_new = m - A[0] if m_new < 0: r2 = False elif m_new == 0: r2 = True elif m_new < min(A[1:]) or len(A) == 1: r2 = False else: r2 = self.rec(m_new,A[1:]) if r1 or r2: return True else: return False if __name__ == "__main__": MC = MyClass() MC.main()
s387658587
p02271
u796784914
1497091177
Python
Python
py
Runtime Error
0
0
435
from collections import deque import numpy as np def main(): n = input() A = deque(map(int,raw_input().split())) q = input() M = map(int,raw_input().split()) a = np.array([0]) p = rec(a,A) for m in M: print "yes" if m in p else "no" def rec(a,A): if len(A) == 0: return a else: a = np.append(a,a+A.popleft()) return rec(a,A) if __name__ == "__main__": main()
s857218090
p02271
u796784914
1497091308
Python
Python
py
Runtime Error
0
0
435
from collections import deque import numpy as np def main(): n = input() A = deque(map(int,raw_input().split())) q = input() M = map(int,raw_input().split()) a = np.array([0]) p = rec(a,A) for m in M: print "yes" if m in p else "no" def rec(a,A): if len(A) == 0: return a else: a = np.append(a,a+A.popleft()) return rec(a,A) if __name__ == "__main__": main()
s898047884
p02271
u264972437
1501153561
Python
Python3
py
Runtime Error
0
0
412
def solve(i,m): if m == 0: return True if i >= n: return False res = solve(i+1,m) or solve(i+1,m-A[i]) return res n = int(input()) A = input() A = [int(s) for s in A.split()] q = int(input()) m = input() m = [int(s) for s in m.split()] ans = '' s = sum(A) for mm in m: if s < mm: ans += 'no' else: ans += solve(0,mm) #ans = [{True:'yes',False:'no'}[solve(0,mm)] for mm in m] print('\n'.join(ans))
s957953192
p02271
u491916705
1502243462
Python
Python
py
Runtime Error
0
0
586
wimport numpy as np n = int(raw_input()) data = map(int, raw_input().split()) m = int(raw_input()) test = map(int, raw_input().split()) # def solve(i,left): # if left == 0: # return True # elif i >= n: # return False # return solve(i+1, left) or solve(i+1, left - data[i]) # for j in range(m): # if solve(0, test[j]): # print 'yes' # else: # print 'no' a = [0] for i in range(n): a = a + [a[j] + data[i] for j in range(len(a))] for i in range(m): if test[i] in a: print 'yes' else: print 'no'
s254645838
p02271
u491916705
1502243536
Python
Python
py
Runtime Error
0
0
586
wimport numpy as np n = int(raw_input()) data = map(int, raw_input().split()) m = int(raw_input()) test = map(int, raw_input().split()) # def solve(i,left): # if left == 0: # return True # elif i >= n: # return False # return solve(i+1, left) or solve(i+1, left - data[i]) # for j in range(m): # if solve(0, test[j]): # print 'yes' # else: # print 'no' a = [0] for i in range(n): a = a + [a[j] + data[i] for j in range(len(a))] for i in range(m): if test[i] in a: print 'yes' else: print 'no'
s552551361
p02271
u285015144
1503632069
Python
Python3
py
Runtime Error
0
0
442
import numpy as np n = input() n = int(n) a = input() a = a.split() a = [int(x) for x in a] q = input() q = int(q) ms = input() ms = ms.split() ms = [int(x) for x in ms] np.sort(a) a = np.array(a) for m in ms: if m > a[-1]: print("no") elif a.any()==m: print("yes") else: a_new = a[a < m] print(a_new) select = [] length = len(a_new) selects = np.zeros(2**length, length)
s165002846
p02271
u153665391
1506082459
Python
Python3
py
Runtime Error
0
0
526
def exhaustive_search(start, Sum, answer): for i in range(start, n): Sum = Sum + A[i] if Sum == answer: return True elif Sum > answer: Sum = Sum - A[i] next else: r = exhaustive_search(i+1, Sum, answer) if r == True: return True else: Sum = Sum - A[i] return False for i in M: r = exhaustive_search(0, 0, i) if r == True: print('yes') else: print('no')
s342391935
p02271
u153665391
1506082525
Python
Python3
py
Runtime Error
0
0
526
def exhaustive_search(start, Sum, answer): for i in range(start, n): Sum = Sum + A[i] if Sum == answer: return True elif Sum > answer: Sum = Sum - A[i] next else: r = exhaustive_search(i+1, Sum, answer) if r == True: return True else: Sum = Sum - A[i] return False for i in M: r = exhaustive_search(0, 0, i) if r == True: print('yes') else: print('no')
s522352650
p02271
u153665391
1506082547
Python
Python3
py
Runtime Error
0
0
526
def exhaustive_search(start, Sum, answer): for i in range(start, n): Sum = Sum + A[i] if Sum == answer: return True elif Sum > answer: Sum = Sum - A[i] next else: r = exhaustive_search(i+1, Sum, answer) if r == True: return True else: Sum = Sum - A[i] return False for i in M: r = exhaustive_search(0, 0, i) if r == True: print('yes') else: print('no')
s501163060
p02271
u153665391
1506082686
Python
Python3
py
Runtime Error
0
0
536
def exhaustive_search(start, Sum, answer): for i in range(start, n): Sum = Sum + A[i] if Sum == answer: return True elif Sum > answer: Sum = Sum - A[i] next else: r = exhaustive_search(i+1, Sum, answer) if r == True: return True else: Sum = Sum - A[i] return False for i in M: r = exhaustive_search(0, 0, i) if r == True: print('yes') else: print('no') return 0
s098276643
p02271
u153665391
1506083060
Python
Python3
py
Runtime Error
0
0
536
def exhaustive_search(start, Sum, answer): for i in range(start, n): Sum = Sum + A[i] if Sum == answer: return True elif Sum > answer: Sum = Sum - A[i] next else: r = exhaustive_search(i+1, Sum, answer) if r == True: return True else: Sum = Sum - A[i] return False for i in M: r = exhaustive_search(0, 0, i) if r == True: print('yes') else: print('no') print('')
s799089717
p02271
u153665391
1506083065
Python
Python3
py
Runtime Error
0
0
537
def exhaustive_search(start, Sum, answer): for i in range(start, n): Sum = Sum + A[i] if Sum == answer: return True elif Sum > answer: Sum = Sum - A[i] next else: r = exhaustive_search(i+1, Sum, answer) if r == True: return True else: Sum = Sum - A[i] return False for i in M: r = exhaustive_search(0, 0, i) if r == True: print('yes') else: print('no') print(' ')
s621555855
p02271
u153665391
1506083078
Python
Python3
py
Runtime Error
0
0
537
def exhaustive_search(start, Sum, answer): for i in range(start, n): Sum = Sum + A[i] if Sum == answer: return True elif Sum > answer: Sum = Sum - A[i] next else: r = exhaustive_search(i+1, Sum, answer) if r == True: return True else: Sum = Sum - A[i] return False for i in M: r = exhaustive_search(0, 0, i) if r == True: print('yes') else: print('no') print(?\n)
s414079347
p02271
u798803522
1509464229
Python
Python3
py
Runtime Error
30
7704
435
a_len = int(input()) a_ar = sorted([int(n) for n in input().split(" ")]) b_len = int(input()) b_ar = [int(n) for n in input().split(" ")] max_b = max(b_ar) dp = [0 for n in range(max_b + 1)] for a in a_ar: new_dp = dp[:] new_dp[a] = 1 for i,d in enumerate(dp): if d and i + a <= max_b + 1: new_dp[i + a] = 1 dp = new_dp for b in b_ar: if dp[b]: print("yes") else: print("no")
s425685471
p02271
u626266743
1510157445
Python
Python3
py
Runtime Error
0
0
345
n = int(input()) A = list(map(int, input().split())) q = int(input()) mi = map(int, input().split()) def solve(i, m): if (m == 0): return True if (i >= n): return False res = solve(i + 1, m) or solve(i + 1, m - A[i]) return res for i in mi: if solve(0, m): print("yes") else: print("no")
s819000500
p02271
u626266743
1510157632
Python
Python3
py
Runtime Error
0
0
345
n = int(input()) A = list(map(int, input().split())) q = int(input()) mi = map(int, input().split()) def solve(i, m): if (m == 0): return True if (i >= n): return False res = solve(i + 1, m) or solve(i + 1, m - A[i]) return res for i in q: if solve(0, mi): print("yes") else: print("no")
s020935014
p02271
u626266743
1510157724
Python
Python3
py
Runtime Error
0
0
352
n = int(input()) A = list(map(int, input().split())) q = int(input()) mi = map(int, input().split()) def solve(i, m): if (m == 0): return True if (i >= n): return False res = solve(i + 1, m) or solve(i + 1, m - A[i]) return res for i in range(q): if solve(0, mi): print("yes") else: print("no")
s765337283
p02271
u626266743
1510157844
Python
Python3
py
Runtime Error
0
0
357
n = int(input()) A = list(map(int, input().split())) q = int(input()) mi = set(map(int, input().split())) def solve(i, m): if (m == 0): return True if (i >= n): return False res = solve(i + 1, m) or solve(i + 1, m - A[i]) return res for i in range(q): if solve(0, mi): print("yes") else: print("no")
s404925938
p02271
u626266743
1510660603
Python
Python3
py
Runtime Error
0
0
352
n = int(input()) A = list(map(int, input().split())) q = int(input()) mi = map(int, input().split()) def solve(i, m): if (m == 0): return True if (i >= n): return False res = solve(i + 1, m) or solve(i + 1, m - A[i]) return res for i in range(q): if solve(0, mi): print("yes") else: print("no")
s536529731
p02271
u626266743
1510660660
Python
Python3
py
Runtime Error
0
0
352
n = int(input()) A = list(map(int, input().split())) q = int(input()) mi = map(int, input().split()) def solve(i, m): if (m == 0): return True if (i >= n): return False res = solve(i + 1, m) or solve(i + 1, m - A[i]) return res for i in range(q): if solve(0, mi): print("yes") else: print("no")
s154218089
p02271
u626266743
1510660890
Python
Python3
py
Runtime Error
0
0
352
n = int(input()) A = list(map(int, input().split())) q = int(input()) mi = map(int, input().split()) def solve(i, m): if (m == 0): return True if (i >= n): return False res = solve(i + 1, m) or solve(i + 1, m - A[i]) return res for j in range(q): if solve(0, mi): print("yes") else: print("no")
s218803579
p02271
u626266743
1510661456
Python
Python3
py
Runtime Error
0
0
352
n = int(input()) A = list(map(int, input().split())) q = int(input()) mi = map(int, input().split()) def solve(i, m): if (m == 0): return True if (i >= n): return False res = solve(i + 1, m) or solve(i + 1, m - A[i]) return res for j in range(q): if solve(0, mi): print("yes") else: print("no")
s832966327
p02271
u626266743
1510661857
Python
Python3
py
Runtime Error
0
0
371
n = int(input()) A = list(map(int, input().split())) q = int(input()) mi = map(int, input().split()) S = {} def solve(i, m): if (m == 0): return True if (i >= n): return False res = solve(i + 1, m) or solve(i + 1, m - A[i]) return res for j in range(1, q + 1): if solve(0, mi): print("yes") else: print("no")
s068337859
p02271
u626266743
1510661883
Python
Python3
py
Runtime Error
0
0
364
n = int(input()) A = list(map(int, input().split())) q = int(input()) mi = map(int, input().split()) S = {} def solve(i, m): if (m == 0): return True if (i >= n): return False res = solve(i + 1, m) or solve(i + 1, m - A[i]) return res for j in range(q): if solve(0, mi): print("yes") else: print("no")
s023571336
p02271
u626266743
1510662057
Python
Python3
py
Runtime Error
0
0
429
n = int(input()) A = list(map(int, input().split())) q = int(input()) mi = map(int, input().split()) tmp = {} def solve(i, m): if (m == 0): return True if (i >= n): return False if (i,m) in tmp: return tmp[(i,m)] res = solve(i + 1, m) or solve(i + 1, m - A[i]) tmp[(i,m)] = res return res for j in range(q): if solve(0, mi): print("yes") else: print("no")
s419861329
p02271
u626266743
1510662077
Python
Python3
py
Runtime Error
0
0
421
n = int(input()) A = list(map(int, input().split())) q = int(input()) mi = map(int, input().split()) t = {} def solve(i, m): if (m == 0): return True if (i >= n): return False if (i,m) in t: return t[(i,m)] res = solve(i + 1, m) or solve(i + 1, m - A[i]) t[(i,m)] = res return res for j in range(q): if solve(0, mi): print("yes") else: print("no")
s512133231
p02271
u424457654
1510672838
Python
Python3
py
Runtime Error
0
0
365
n = int(input()) A = list(map(int, input().split())) q = int(input()) m = list(map(int, input().split())) def solve(i, m): if m == 0: return True if i >= n : return False res = solve(i + 1, m) or solve(i + 1, m - a[i]) return res for tmp_m in m: if sum(a) < tmp_m: print('no') elif solve(0, tmp_m): print('yes') else: print('no')
s819040341
p02271
u845643816
1510712172
Python
Python3
py
Runtime Error
0
0
363
n = int(sys.stdin.readline()) A = list(map(int, input().split())) q = int(input()) M = list(map(int, input().split())) def solve(i, m): if m == 0: return True elif i >= n: return False res = solve(i + 1, m) or solve(i + 1, m - A[i]) return res for m in M: if solve(0, m): print('yes') else: print('no')
s239572457
p02271
u845643816
1510713097
Python
Python3
py
Runtime Error
0
0
470
n = int(input()) A = list(map(int, input().split())) q = int(input()) M = list(map(int, input().split())) table = [[0]*max(M)]*n def solve(i, m): if m == 0: return True elif i >= n: return False elif table[i][m] != 0: return table[i][m] else: res = solve(i + 1, m) or solve(i + 1, m - A[i]) table[i][m] = res return res for m in M: if solve(0, m): print('yes') else: print('no')
s569322393
p02271
u845643816
1510713314
Python
Python3
py
Runtime Error
0
0
502
n = int(input()) A = list(map(int, input().split())) q = int(input()) M = list(map(int, input().split())) table = [[0 for i in range(max(M))] for j in range(n)] def solve(i, m): if m == 0: return True elif i >= n: return False elif table[i][m] != 0: return table[i][m] else: res = solve(i + 1, m) or solve(i + 1, m - A[i]) table[i][m] = res return res for m in M: if solve(0, m): print('yes') else: print('no')
s569567002
p02271
u845643816
1510713395
Python
Python3
py
Runtime Error
0
0
502
n = int(input()) A = list(map(int, input().split())) q = int(input()) M = list(map(int, input().split())) table = [[0 for i in range(n)] for j in range(max(M))] def solve(i, m): if m == 0: return True elif i >= n: return False elif table[i][m] != 0: return table[i][m] else: res = solve(i + 1, m) or solve(i + 1, m - A[i]) table[i][m] = res return res for m in M: if solve(0, m): print('yes') else: print('no')
s360084446
p02271
u845643816
1510713578
Python
Python3
py
Runtime Error
0
0
504
n = int(input()) A = list(map(int, input().split())) q = int(input()) M = list(map(int, input().split())) table = [[0 for i in range(n)] for j in range(max(M)+1)] def solve(i, m): if m == 0: return True elif i >= n: return False elif table[i][m] != 0: return table[i][m] else: res = solve(i + 1, m) or solve(i + 1, m - A[i]) table[i][m] = res return res for m in M: if solve(0, m): print('yes') else: print('no')
s029874904
p02271
u845643816
1510713711
Python
Python3
py
Runtime Error
30
7668
504
n = int(input()) A = list(map(int, input().split())) q = int(input()) M = list(map(int, input().split())) table = [[0 for i in range(max(M)+1)] for j in range(n)] def solve(i, m): if m == 0: return True elif i >= n: return False elif table[i][m] != 0: return table[i][m] else: res = solve(i + 1, m) or solve(i + 1, m - A[i]) table[i][m] = res return res for m in M: if solve(0, m): print('yes') else: print('no')
s276587969
p02271
u548155360
1512300861
Python
Python3
py
Runtime Error
13600
5616
659
# coding=utf-8 def is_made_sum(array: list, target: int) -> bool: if target == 0: return True elif target < 0: return False elif not array: return False else: choice = array[0] result1 = is_made_sum(array[1:], target) result2 = is_made_sum(array[1:], target - choice) return result1 | result2 if __name__ == '__main__': n = int(input()) A = list(map(int, input().split())) q = int(input()) M = list(map(int, input().split())) for i in range(q): answer = is_made_sum(A, M[i]) if answer: print('yes') else: print('no')
s973037946
p02271
u548155360
1512301436
Python
Python3
py
Runtime Error
13400
5616
659
# coding=utf-8 def is_made_sum(array: list, target: int) -> bool: if target == 0: return True elif target < 0: return False elif not array: return False else: choice = array[0] result1 = is_made_sum(array[1:], target) result2 = is_made_sum(array[1:], target - choice) return result1 | result2 if __name__ == '__main__': n = int(input()) A = list(map(int, input().split())) q = int(input()) M = list(map(int, input().split())) for i in range(q): answer = is_made_sum(A, M[i]) if answer: print('yes') else: print('no')
s673882612
p02271
u548155360
1512301734
Python
Python3
py
Runtime Error
13430
5616
660
# coding=utf-8 def is_made_sum(array: list, target: int) -> bool: if target == 0: return True elif target < 0: return False elif not array: return False else: choice = array[0] result1 = is_made_sum(array[1:], target) result2 = is_made_sum(array[1:], target - choice) return result1 or result2 if __name__ == '__main__': n = int(input()) A = list(map(int, input().split())) q = int(input()) M = list(map(int, input().split())) for i in range(q): answer = is_made_sum(A, M[i]) if answer: print('yes') else: print('no')
s213990783
p02271
u539789745
1513179513
Python
Python3
py
Runtime Error
16840
5624
694
def main(): """ 2^20 = 1,048,576 q = 200 200,000,000 limit 5s ???????????????OK """ n = int(input()) A = list(map(int, input().split())) q = int(input()) M = map(int, input().split()) for m in M: if solve(m, A, n): print("yes") else: print("no") def solve(m, A, n): for b in f(n): s = sum(a * bit for a, bit in zip(A, b)) if m == s: return True return False def f(n): for i in range(2 ** n): # 0/1???n??????????????????bit????????¨ # 0b ????????? bit = bin(i)[2:] yield map(int, bit.zfill(n)) if __name__ == '__main__': main()
s453867818
p02271
u539789745
1513180972
Python
Python3
py
Runtime Error
5530
5680
780
from itertools import product def main(): """ 2^20 = 1,048,576 q = 200 200,000,000 limit 5s ???????????????OK """ n = int(input()) A = list(map(int, input().split())) q = int(input()) M = map(int, input().split()) for m in M: if m == 0 or solve(m, A, n): print("yes") else: print("no") def solve(m, A, n): # for b in f1(n): for b in product([0, 1], repeat=n): s = sum(a * bit for a, bit in zip(A, b)) if m == s: return True return False def f1(n): for i in range(2 ** n): # 0/1???n??????????????????bit????????¨ # 0b ????????? bit = bin(i)[2:] yield map(int, bit.zfill(n)) if __name__ == '__main__': main()
s978740013
p02271
u530663965
1514077195
Python
Python3
py
Runtime Error
6680
5616
551
def main(): base = get_input() li = get_input() base.sort() for l in li: if check_list(base, 0, l, len(base)): print('yes') else: print('no') def check_list(base, idx, key, length): if key == 0: return True elif idx >= length: return False res = check_list(base, idx + 1, key, length) or check_list(base, idx + 1, key - base[idx], length) return res def get_input(): _ = int(input()) li = [int(x) for x in input().split(' ')] return li main()
s717277503
p02271
u530663965
1514077237
Python
Python3
py
Runtime Error
6720
5616
593
import sys sys.setrecursionlimit(10000) def main(): base = get_input() li = get_input() base.sort() for l in li: if check_list(base, 0, l, len(base)): print('yes') else: print('no') def check_list(base, idx, key, length): if key == 0: return True elif idx >= length: return False res = check_list(base, idx + 1, key, length) or check_list(base, idx + 1, key - base[idx], length) return res def get_input(): _ = int(input()) li = [int(x) for x in input().split(' ')] return li main()
s975481521
p02271
u585035894
1514625757
Python
Python3
py
Runtime Error
9670
5612
343
input() a = [int(i) for i in input().split()] def solve(i, m): if m == 0: return True if i >= len(a): return False return solve(i+1, m) or solve(i+1, m - a[i]) # m - a[i] ??§????????°???????????£??????????????????????????? input() for i in input().split(): print('yes') if solve(0, int(i)) else print('no')
s289550475
p02271
u585035894
1514627734
Python
Python3
py
Runtime Error
9750
5620
384
import sys sys.setrecursionlimit(10000) input() a = [int(i) for i in input().split()] def solve(i, m): if m == 0: return True if i >= len(a): return False return solve(i+1, m) or solve(i+1, m - a[i]) # m - a[i] ??§????????°???????????£??????????????????????????? input() for i in input().split(): print('yes') if solve(0, int(i)) else print('no')
s958612052
p02271
u426534722
1516717359
Python
Python3
py
Runtime Error
5560
5656
353
from itertools import combinations n = int(input()) A = tuple(map(int, input().split())) def solve(m): if m in A: return "yes" for i in range(2, n + 1): for C in combinations(A, i): if sum(C) == m: return "yes" return "no" q = int(input()) for m in map(int, input().split()): print(solve(m))
s815348491
p02271
u426534722
1516718051
Python
Python3
py
Runtime Error
2640
5652
414
from itertools import combinations n = int(input()) A = tuple(map(int, input().split())) SET = set(A) def solve(m): if m in A: return "yes" for i in range(1, n): for C in combinations(A, i): sumC = sum(C) if sumC < m and m - sumC in SET - set(C): return "yes" return "no" q = int(input()) for m in map(int, input().split()): print(solve(m))
s821833052
p02271
u426534722
1516718495
Python
Python3
py
Runtime Error
5640
15628
411
from itertools import combinations n = int(input()) A = tuple(map(int, input().split())) SET = set(A) def solve(m): if m in A: return "yes" dp = [0] for a in A: q = [] for d in dp: q.append(d) q.append(d + a) dp = q if m in dp: return "yes" return "no" q = int(input()) for m in map(int, input().split()): print(solve(m))
s211551433
p02271
u662418022
1517046375
Python
Python3
py
Runtime Error
8510
5620
489
# -*- coding: utf-8 -*- if __name__ == '__main__': n = int(input()) A = [int(a) for a in input().split(" ")] q = int(input()) M = [int(m) for m in input().split(" ")] def solve(i, m): if m == 0: return True if i >= n: return False res = solve(i+1, m) or solve(i+1, m-A[i]) return res for m in M: if solve(0, m)==True: print("yes") else: print("no")
s159316119
p02271
u662418022
1517046538
Python
Python3
py
Runtime Error
7490
5616
489
# -*- coding: utf-8 -*- if __name__ == '__main__': n = int(input()) A = [int(a) for a in input().split(" ")] q = int(input()) M = [int(m) for m in input().split(" ")] def solve(i, m): if m == 0: return True if i >= n: return False res = solve(i+1, m) or solve(i+1, m-A[i]) return res for m in M: if solve(0, m)==True: print("yes") else: print("no")
s626069506
p02271
u662418022
1517046699
Python
Python3
py
Runtime Error
8030
5612
526
# -*- coding: utf-8 -*- if __name__ == '__main__': n = int(input()) A = [int(a) for a in input().split(" ")] q = int(input()) M = [int(m) for m in input().split(" ")] def solve(i, m): if m == 0: return True if i >= n: return False res = solve(i+1, m) or solve(i+1, m-A[i]) return res ans = [] for m in M: if solve(0, m)==True: ans.append("yes") else: ans.append("no") print("\n".join(ans))
s634229506
p02271
u749243807
1517067731
Python
Python3
py
Runtime Error
0
0
411
A_count = int(input()); A = [int(n) for n in input().split()]; M_count = int(input()); M = [int(n) for n in input().split]; def solve(start, target): if target == 0: return True; elif start >= n: return False: else: return solve(start + 1, target) || solve(start + 1, target - A[start]); for m in M: if solve(0, m): print("yes"); else: print("no");
s317360636
p02271
u749243807
1517067820
Python
Python3
py
Runtime Error
7260
5616
419
A_count = int(input()); A = [int(n) for n in input().split()]; M_count = int(input()); M = [int(n) for n in input().split()]; def solve(start, target): if target == 0: return True; elif start >= A_count: return False; else: return solve(start + 1, target) or solve(start + 1, target - A[start]); for m in M: if solve(0, m): print("yes"); else: print("no");
s560917979
p02271
u749243807
1517067962
Python
Python3
py
Runtime Error
7580
5616
419
A_count = int(input()); A = [int(n) for n in input().split()]; M_count = int(input()); M = [int(n) for n in input().split()]; def solve(start, target): if target == 0: return True; elif start >= A_count: return False; else: return solve(start + 1, target) or solve(start + 1, target - A[start]); for m in M: if solve(0, m): print("yes"); else: print("no");
s606427376
p02271
u749243807
1517069265
Python
Python3
py
Runtime Error
0
0
725
A_count = int(input()); A = [int(n) for n in input().split()]; M_count = int(input()); M = [int(n) for n in input().split()]; memo = [[None for i in range(2000)] for j in range(A_count)]; def solve(start, target): if memo[start][target] is not None: return memo[start][target]; if target == 0: return True; elif start >= A_count: return False; else: result = solve(start + 1, target) or solve(start + 1, target - A[start]); if result: memo[start][target] = True; return True; else: memo[start][target] = False; return False; for m in M: if solve(0, m): print("yes"); else: print("no");
s472276972
p02271
u208157605
1518041252
Python
Python3
py
Runtime Error
7450
5612
366
def solve(i, m): if m == 0: return True elif i >= n: return False res = solve(i + 1, m) or solve(i + 1, m - arr[i]) return res n = int(input()) arr = list(map(int, input().split())) q = input() requests = list(map(int, input().split())) for req in requests: if solve(0, req): print('yes') else: print('no')
s203170058
p02271
u177808190
1518186098
Python
Python3
py
Runtime Error
8300
5616
394
def exSearch(i, m, hoge): if m == 0: return True if i >= len(hoge): return False res = exSearch(i+1, m, hoge) or exSearch(i+1, m-hoge[i], hoge) return res _ = int(input()) hoge = [int(x) for x in input().split()] _ = int(input()) for val in (int(x) for x in input().split()): if exSearch(0, val, hoge): print ('yes') else: print ('no')
s906277575
p02271
u177808190
1518186142
Python
Python3
py
Runtime Error
9030
5612
394
def exSearch(i, m, hoge): if m == 0: return True if i >= len(hoge): return False res = exSearch(i+1, m, hoge) or exSearch(i+1, m-hoge[i], hoge) return res _ = int(input()) hoge = [int(x) for x in input().split()] _ = int(input()) for val in (int(x) for x in input().split()): if exSearch(0, val, hoge): print ('yes') else: print ('no')
s837205995
p02271
u177808190
1518186474
Python
Python3
py
Runtime Error
8750
5616
453
def exSearch(i, m, hoge): if m == 0: return True if i >= len(hoge): return False res = exSearch(i+1, m, hoge) or exSearch(i+1, m-hoge[i], hoge) return res if __name__ == '__main__': _ = int(input()) hoge = [int(x) for x in input().split()] _ = int(input()) for val in (int(x) for x in input().split()): if exSearch(0, val, hoge): print ('yes') else: print ('no')
s886214169
p02271
u177808190
1518186802
Python
Python3
py
Runtime Error
9210
5616
422
_ = int(input()) hoge = [int(x) for x in input().split()] _ = int(input()) def exSearch(i, m): if m == 0: return True if i >= len(hoge): return False res = exSearch(i+1, m) or exSearch(i+1, m-hoge[i]) return res if __name__ == '__main__': for val in (int(x) for x in input().split()): if exSearch(0, val): print ('yes') else: print ('no')
s942947449
p02271
u177808190
1518186907
Python
Python3
py
Runtime Error
0
0
372
num_n = int(input()) n = map(int, input().split()) num_m = int(input()) m = map(int, input().split()) def solve(i, m): if m == 0: return True if i >= num_n or m > sum(n): return False res = solve(i + 1, m) or solve(i + 1,m - n[i]) return res for k in range(num_m): if solve(0, m[k]): print ("yes") else: print ("no")
s603526778
p02271
u996463517
1518325361
Python
Python3
py
Runtime Error
6980
8024
457
def solve(a,m): S = [] ans = [] tmp = 0 for i in range(1,2**len(a)): S.append(str(format(i,'b').zfill(len(a)))) for s in S: for j in range(len(a)): if s[j] == '1': tmp += a[j] if tmp == m:return 'yes' tmp = 0 else:return 'no' n = int(input()) a = [int(i) for i in input().split()] q = int(input()) M = [int(i) for i in input().split()] for m in M: print(solve(a,m))
s795017204
p02271
u996463517
1518326382
Python
Python3
py
Runtime Error
6840
5612
351
def solve2(i,m,a,n): if m == 0: return True if i >= n: return False res = solve2(i+1,m,a,n) or solve2(i+1,m-a[i],a,n) return res n = int(input()) a = [int(i) for i in input().split()] q = int(input()) M = [int(i) for i in input().split()] for m in M: if solve2(0,m,a,n): print('yes') else: print('no')
s655141995
p02271
u996463517
1518326677
Python
Python3
py
Runtime Error
0
0
375
@functools.lru_cache() def solve2(i,m,a,n): if m == 0: return True if i >= n: return False res = solve2(i+1,m,a,n) or solve2(i+1,m-a[i],a,n) return res n = int(input()) a = [int(i) for i in input().split()] q = int(input()) M = [int(i) for i in input().split()] for m in M: if solve2(0,m,a,n): print('yes') else: print('no')
s809876291
p02271
u996463517
1518326695
Python
Python3
py
Runtime Error
0
0
374
@functools.lru_cache() def solve2(i,m,a,n): if m == 0: return True if i >= n: return False res = solve2(i+1,m,a,n) or solve2(i+1,m-a[i],a,n) return res n = int(input()) a = [int(i) for i in input().split()] q = int(input()) M = [int(i) for i in input().split()] for m in M: if solve2(0,m,a,n): print('yes') else: print('no')
s867865220
p02271
u996463517
1518326817
Python
Python3
py
Runtime Error
9110
6292
393
import functools @functools.lru_cache() def solve2(i,m,): if m == 0: return True if i >= n: return False res = solve2(i+1,m) or solve2(i+1,m-a[i]) return res global n global a n = int(input()) a = [int(i) for i in input().split()] q = int(input()) M = [int(i) for i in input().split()] for m in M: if solve2(0,m): print('yes') else: print('no')
s879197396
p02271
u150984829
1518627252
Python
Python3
py
Runtime Error
0
0
234
n=int(input()) A=list(map(int,input().split())) r=set() def f(s,k): if k>=0: global r r|=set(s) f(s+A[k-1],k-1) f(s,k-1) f(0,n) input() for e in map(int,input().split()):print(['no','yes'][e in r])
s571055719
p02271
u238001675
1519626818
Python
Python3
py
Runtime Error
4860
5620
528
#!/usr/bin/python3 # -*- coding: utf-8 -*- def solve(p, t, A): if A[p] == t: return True if len(A)-1 == p: return False if solve(p+1, t-A[p], A): return True if solve(p+1, t, A): return True return False import sys n = int(sys.stdin.readline()) A = list(map(int, sys.stdin.readline().split())) num_q = int(sys.stdin.readline()) query = list(map(int, sys.stdin.readline().split())) for m in query: if solve(0, m, A): print('yes') else: print('no')
s375620522
p02271
u912143677
1520320967
Python
Python3
py
Runtime Error
7440
5608
329
n = int(input()) a = list(map(int, input().split())) q = int(input()) m = list(map(int, input().split())) def f(i, m): if m == 0: return True elif i >= n: return False elif f(i+1, m): return True elif f(i+1, m-a[i]): return True for k in m: print('yes' if f(0, k) else 'no')
s942248901
p02271
u912143677
1520321390
Python
Python3
py
Runtime Error
9160
5612
367
n = int(input()) a = list(map(int, input().split())) q = int(input()) m = list(map(int, input().split())) def f(i, m): if m == 0: return True elif m < 0: return False elif i >= n: return False elif f(i+1, m): return True elif f(i+1, m-a[i]): return True for k in m: print('yes' if f(0, k) else 'no')
s051620960
p02271
u613534067
1520838462
Python
Python3
py
Runtime Error
16850
5608
433
def calc(a, m, x): if a == []: return False y = a[0] if x == m: return True elif (x + y) == m: return True else: return calc(a[1:], m, x) or calc(a[1:], m, x + y) or calc(a[1:], m, y) n = int(input()) a = list(map(int, input().split())) q = int(input()) m = list(map(int, input().split())) for mi in m: if calc(a[:], mi, 0): print("yes") else: print("no")
s713964311
p02271
u613534067
1520838715
Python
Python3
py
Runtime Error
10260
5612
412
def calc(a, m, x): if a == []: return False y = a[0] if x == m: return True elif (x + y) == m: return True else: return calc(a[1:], m, x) or calc(a[1:], m, x + y) n = int(input()) a = list(map(int, input().split())) q = int(input()) m = list(map(int, input().split())) for mi in m: if calc(a[:], mi, 0): print("yes") else: print("no")
s296121266
p02271
u613534067
1520838995
Python
Python3
py
Runtime Error
9890
5612
412
def calc(a, m, x): if a == []: return False y = a[0] if x == m: return True elif (x + y) == m: return True else: return calc(a[1:], m, x) or calc(a[1:], m, x + y) n = int(input()) a = list(map(int, input().split())) q = int(input()) m = list(map(int, input().split())) for mi in m: if calc(a[:], mi, 0): print("yes") else: print("no")
s111178478
p02271
u613534067
1520839176
Python
Python3
py
Runtime Error
9860
5612
409
def calc(a, m, x): if a == []: return False y = a[0] if x == m: return True elif (x + y) == m: return True else: return calc(a[1:], m, x + y) or calc(a[1:], m, x) n = int(input()) a = list(map(int, input().split())) q = int(input()) m = list(map(int, input().split())) for mi in m: if calc(a, mi, 0): print("yes") else: print("no")
s303889085
p02271
u613534067
1520839523
Python
Python3
py
Runtime Error
9420
5612
372
def calc(a, m, x): if a == []: return False y = a[0] if (x + y) == m: return True else: return calc(a[1:], m, x) or calc(a[1:], m, x + y) n = int(input()) a = list(map(int, input().split())) q = int(input()) m = list(map(int, input().split())) for mi in m: if calc(a, mi, 0): print("yes") else: print("no")
s902206378
p02271
u152639966
1521747812
Python
Python3
py
Runtime Error
12610
5612
264
n=int(input()) A=input().split(' ') q=input() M=input().split(' ') def solve(i,m): if m==0: return(True) if i>=n: return(False) res=solve(i+1,m) or solve(i+1,m-int(A[i])) return(res) for j in M: if solve(0,int(j)): print('yes') else: print('no')
s014283428
p02271
u912143677
1522388594
Python
Python3
py
Runtime Error
10480
5608
366
n = int(input()) a = list(map(int, input().split())) q = int(input()) m = list(map(int, input().split())) def f(i, m): if m == 0: return True elif m < 0: return False elif i >= n: return False elif f(i+1, m): return True elif f(i+1, m-a[i]): return True for k in m: print('yes' if f(0, k) else 'no')
s748731178
p02271
u912143677
1522388991
Python
Python3
py
Runtime Error
8880
5612
397
n = int(input()) a = list(map(int, input().split())) q = int(input()) m = list(map(int, input().split())) def f(i, m): if m == 0: return True elif m < 0: return False elif i >= n: return False elif f(i+1, m): return True elif f(i+1, m-a[i]): return True else: return False for k in m: print('yes' if f(0, k) else 'no')
s864090472
p02271
u912143677
1522389668
Python
Python3
py
Runtime Error
0
0
542
n = int(input()) a = list(map(int, input().split())) q = int(input()) m = list(map(int, input().split())) memory = [[-1 for i in range(q)]for j in range(n)] def f(i, m): if memory[i][m] != -1: return memory[i][m] if m == 0: return 1 elif m < 0: return 0 elif i >= n: return 0 elif f(i+1, m): memory[i+1][m] = 1 return 1 elif f(i+1, m-a[i]): memory[i+1][m-a[i]] = 1 return 1 else: return 0 for k in m: print('yes' if f(0, k) else 'no')
s132491611
p02271
u091332835
1522390597
Python
Python3
py
Runtime Error
12310
5624
418
n = int(input()) A = list(map(int, input().split())) q = int(input()) m = list(map(int, input().split())) T = pow(2,n)-1 for k in range(q): z = 0 for i in range(T): B = list(format(i,"0"+str(n)+"b")) sum = 0 for j in range(n): sum += A[j]*int(B[j]) if sum == m[k]: z =1 break if z==1: print("yes") else: print("no")
s946568774
p02271
u912143677
1522393336
Python
Python3
py
Runtime Error
0
0
676
n = int(input()) a = list(map(int, input().split())) q = int(input()) m = list(map(int, input().split())) memory = [[-1 for i in range(2000)]for j in range(n)] def f(i, k, sum): if memory[i][sum] != -1: return memory[i][sum] if sum == k: memory[i][sum] = 1 return 1 elif sum > k: memory[i][sum] = 0 return 0 elif i >= n: return 0 else: res0 = f(i+1, k, sum) res1 = f(i+1, k, sum + a[i]) if res0 or res1: memory[i][sum] = 1 return 1 else: memory[i][m] = 0 return 0 for k in m: print('yes' if f(0, k, 0) else 'no')
s079776755
p02271
u912143677
1522395100
Python
Python3
py
Runtime Error
12350
5612
450
n = int(input()) a = list(map(int, input().split())) q = int(input()) m = list(map(int, input().split())) def f(i, m): if m == 0: return 1 elif i >= n: return 0 elif m - a[i] >= 0: res0 = f(i+1, m) res1 = f(i+1, m-a[i]) if res0 or res1: return 1 else: return 0 else: res = f(i+1, m) return res for k in m: print('yes' if f(0, k) else 'no')
s600095616
p02271
u912143677
1522395122
Python
Python3
py
Runtime Error
12270
5612
450
n = int(input()) a = list(map(int, input().split())) q = int(input()) m = list(map(int, input().split())) def f(i, m): if m == 0: return 1 elif i >= n: return 0 elif m - a[i] >= 0: res0 = f(i+1, m) res1 = f(i+1, m-a[i]) if res0 or res1: return 1 else: return 0 else: res = f(i+1, m) return res for k in m: print('yes' if f(0, k) else 'no')
s950434626
p02271
u912143677
1522395139
Python
Python3
py
Runtime Error
12380
5612
450
n = int(input()) a = list(map(int, input().split())) q = int(input()) m = list(map(int, input().split())) def f(i, m): if m == 0: return 1 elif i >= n: return 0 elif m - a[i] >= 0: res0 = f(i+1, m) res1 = f(i+1, m-a[i]) if res0 or res1: return 1 else: return 0 else: res = f(i+1, m) return res for k in m: print('yes' if f(0, k) else 'no')
s071584696
p02271
u091332835
1522400394
Python
Python3
py
Runtime Error
20
5592
511
n = int(input()) A = list(map(int, input().split())) q = int(input()) m = list(map(int, input().split())) def agari(i): if X[i]==1: X[i]=0 agari(i+1) else: X[i]=1 for j in range(q): k = 0 flag = 0 X = [0] * 10 while k<(pow(2,n)-1): y = 0 for l in range(n): y += A[l]*X[l] if y == m[j]: flag = 1 break agari(0) k+=1 if flag == 1: print("yes") else: print("no")
s536288950
p02271
u138546245
1523935298
Python
Python3
py
Runtime Error
19430
92844
1642
class Tree: class Node: def __init__(self, n): self.left = None self.right = None self.n = n def find(self, total): if total == 0: return True elif total < 0: return False if self.left is None: left = (total == self.n) else: left = self.left.find(total-self.n) if self.right is None: right = False else: right = self.right.find(total) return left or right def __str__(self): cs = [] if self.left is not None: cs.append(str(self.left)) if self.right is not None: cs.append(str(self.right)) return "{} -> ({})".format(self.n, ",".join(cs)) def __init__(self, ns): self.top = self.Node(0) self.build_node(self.top, sorted(ns)) def has_subset(self, total): return self.top.find(total) def build_node(self, node, ns): if len(ns) == 0: return node.left = self.Node(ns[-1]) node.right = self.Node(ns[-1]) self.build_node(node.left, ns[:-1]) self.build_node(node.right, ns[:-1]) def run(): _ = int(input()) # flake8: noqa ns = [int(i) for i in input().split()] tree = Tree(ns) _ = int(input()) # flake8: noqa for q in (int(j) for j in input().split()): if tree.has_subset(q): print("yes") else: print("no") if __name__ == '__main__': run()
s528329939
p02271
u138546245
1523936971
Python
Python3
py
Runtime Error
7770
49284
1607
class Tree: class Node: def __init__(self, n): self.left = None self.right = None self.n = n def find(self, total): if total == self.n: return True elif total < self.n: return (self.right is not None and self.right.find(total)) else: return ((self.left is not None and self.left.find(total-self.n)) or (self.right is not None and self.right.find(total))) def __str__(self): cs = [] if self.left is not None: cs.append(str(self.left)) if self.right is not None: cs.append(str(self.right)) return "{} -> ({})".format(self.n, ",".join(cs)) def __init__(self, ns): self.top = self.build_nodes(sorted(ns)) def has_subset(self, total): return self.top.find(total) def build_nodes(self, ns): if len(ns) == 0: return node = self.Node(ns[-1]) node.left = self.build_nodes(ns[:-1]) node.right = self.build_nodes(ns[:-1]) return node def run(): _ = int(input()) # flake8: noqa ns = [int(i) for i in input().split()] tree = Tree(ns) _ = int(input()) # flake8: noqa for q in (int(j) for j in input().split()): if tree.has_subset(q): print("yes") else: print("no") if __name__ == '__main__': run()
s267586890
p02271
u464859367
1524327679
Python
Python3
py
Runtime Error
0
0
404
# jは目的の値, iは要素のリストのキー def solve(i, j): global a, A if j == 0: return True if i >= a: return False # 左はA[i]の要素を使用しない場合、右は使用する場合 res = solve(i + 1, j) or solve(i + 1, j - A[i]) return res for m in M: r = solve(0, m) if r is True: print("yes") else: print("no")
s018715619
p02271
u464859367
1524327695
Python
Python3
py
Runtime Error
7940
5612
515
a = int(input()) A = list(map(int, input().split())) N = int(input()) M = list(map(int, input().split())) # jは目的の値, iは要素のリストのキー def solve(i, j): global a, A if j == 0: return True if i >= a: return False # 左はA[i]の要素を使用しない場合、右は使用する場合 res = solve(i + 1, j) or solve(i + 1, j - A[i]) return res for m in M: r = solve(0, m) if r is True: print("yes") else: print("no")
s287800530
p02271
u464859367
1524328058
Python
Python3
py
Runtime Error
0
0
505
a = input() A = list(map(int, input().split())) N = input() M = list(map(int, input().split())) # jは目的の値, iは要素のリストのキー def solve(i, j): global a, A if j == 0: return True if i >= a: return False # 左はA[i]の要素を使用しない場合、右は使用する場合 res = solve(i + 1, j) or solve(i + 1, j - A[i]) return res for m in M: r = solve(0, m) if r is True: print("yes") else: print("no")
s293785028
p02271
u464859367
1524328089
Python
Python3
py
Runtime Error
7980
5612
510
a = int(input()) A = list(map(int, input().split())) N = input() M = list(map(int, input().split())) # jは目的の値, iは要素のリストのキー def solve(i, j): global a, A if j == 0: return True if i >= a: return False # 左はA[i]の要素を使用しない場合、右は使用する場合 res = solve(i + 1, j) or solve(i + 1, j - A[i]) return res for m in M: r = solve(0, m) if r is True: print("yes") else: print("no")
s283074008
p02271
u126478680
1525246168
Python
Python3
py
Runtime Error
13200
12464
732
import copy combinations = [] def make_combination(n): S = [0 for i in range(n)] rec(0, n, S) def rec(i, n, S): global combinations if i == n: combinations.append(copy.copy(S)) return None rec(i+1, n, S) S[i] = 1 rec(i+1, n, S) S[i] = 0 n = int(input()) A = [int(x) for x in input().split(' ')] q = int(input()) M = [int(x) for x in input().split(' ')] make_combination(n) for m in M: flag = False for co in combinations: sum = 0 for i in range(n): sum += A[i] * co[i] if sum >= m: break if sum == m: flag = True break if flag: print('yes') else: print('no')
s218004328
p02271
u126478680
1525246254
Python
Python3
py
Runtime Error
12610
12468
729
import copy combinations = [] def make_combination(n): S = [0 for i in range(n)] rec(0, n, S) def rec(i, n, S): global combinations if i == n: combinations.append(copy.copy(S)) return None rec(i+1, n, S) S[i] = 1 rec(i+1, n, S) S[i] = 0 n = int(input()) A = list(map(int, input().split(' '))) q = int(input()) M = list(map(int, input().split(' '))) make_combination(n) for m in M: flag = False for co in combinations: sum = 0 for i in range(n): sum += A[i] * co[i] if sum >= m: break if sum == m: flag = True break if flag: print('yes') else: print('no')
s718826848
p02271
u255317651
1525266851
Python
Python3
py
Runtime Error
7020
5672
684
# -*- coding: utf-8 -*- """ Created on Wed May 2 21:28:06 2018 ALDS1_5a @author: maezawa """ import itertools as itr n = int(input()) a = list(map(int, input().split())) q = int(input()) m = list(map(int, input().split())) for i in m: yesorno = False b = [] for j in a: if j <= i: b.append(j) #print(b) if len(b)>=1: for r in range(1, len(b)+1): for comb in itr.combinations(b,r): #print(i,comb) if sum(comb) == i: yesorno = True break if yesorno: break if yesorno: print('yes') else: print('no')
s318987046
p02271
u255317651
1525267666
Python
Python3
py
Runtime Error
7360
5672
684
# -*- coding: utf-8 -*- """ Created on Wed May 2 21:28:06 2018 ALDS1_5a @author: maezawa """ import itertools as itr n = int(input()) a = list(map(int, input().split())) q = int(input()) m = list(map(int, input().split())) for i in m: yesorno = False b = [] for j in a: if j <= i: b.append(j) #print(b) if len(b)>=1: for r in range(1, len(b)+1): for comb in itr.combinations(b,r): #print(i,comb) if sum(comb) == i: yesorno = True break if yesorno: break if yesorno: print('yes') else: print('no')
s542060526
p02271
u255317651
1525270202
Python
Python3
py
Runtime Error
0
0
721
# -*- coding: utf-8 -*- """ Created on Wed May 2 21:28:06 2018 ALDS1_5a @author: maezawa """ import itertools as itr n = int(input()) a = list(map(int, input().split())) q = int(input()) m = list(map(int, input().split())) for i in m: yesorno = False b = [] for j in a: if j <= i: b.append(j) #print(b) lb = len(b) if lb >= 1: for r in range(1, 2**lb): bin_str = format(r, 'b') sumb = sum([b[k]*int(bin_str[k]) for k in range(lb)]) #print(i,comb) if sumb == i: yesorno = True break if yesorno: break if yesorno: print('yes') else: print('no')
s668867754
p02271
u255317651
1525270492
Python
Python3
py
Runtime Error
9510
5692
755
# -*- coding: utf-8 -*- """ Created on Wed May 2 21:28:06 2018 ALDS1_5a @author: maezawa """ import itertools as itr n = int(input()) a = list(map(int, input().split())) q = int(input()) m = list(map(int, input().split())) for i in m: yesorno = False b = [] for j in a: if j <= i: b.append(j) #print(b) lb = len(b) if lb >= 1: for r in range(1, 2**lb): fmt = '0'+str(lb)+'b' bin_str = format(r, fmt) sumb = sum([b[k]*int(bin_str[k]) for k in range(lb)]) #print(i,comb) if sumb == i: yesorno = True break if yesorno: break if yesorno: print('yes') else: print('no')
s322116217
p02271
u255317651
1525305501
Python
Python3
py
Runtime Error
0
0
480
# -*- coding: utf-8 -*- """ Created on Wed May 2 21:28:06 2018 ALDS1_5a @author: maezawa """ import itertools as itr n = int(input()) a = list(map(int, input().split())) q = int(input()) m = list(map(int, input().split())) sum_array = [] for r in range(1,n+1): for comb in itr.combinations(a, r): aum_array.append[sum(comb)] for i in m: yesorno = 'no' for j in sum_array: if i == j: yesorno == 'yes' break print('yes')
s694405610
p02271
u255317651
1525305534
Python
Python3
py
Runtime Error
0
0
480
# -*- coding: utf-8 -*- """ Created on Wed May 2 21:28:06 2018 ALDS1_5a @author: maezawa """ import itertools as itr n = int(input()) a = list(map(int, input().split())) q = int(input()) m = list(map(int, input().split())) sum_array = [] for r in range(1,n+1): for comb in itr.combinations(a, r): sum_array.append[sum(comb)] for i in m: yesorno = 'no' for j in sum_array: if i == j: yesorno == 'yes' break print('yes')
s335596441
p02271
u255317651
1525316662
Python
Python3
py
Runtime Error
7020
5632
612
# -*- coding: utf-8 -*- """ Created on Thu May 3 11:39:47 2018 @author: maezawa """ # -*- coding: utf-8 -*- """ Created on Wed May 2 21:28:06 2018 ALDS1_5a_r2 @author: maezawa """ n = int(input()) a = list(map(int, input().split())) q = int(input()) m_array = list(map(int, input().split())) def can_comp(i, m): #i番目以降の数列をつかってmを作れるか? if m == 0: return True elif i == n: return False else: return can_comp(i+1, m) or can_comp(i+1, m-a[i]) for m in m_array: if can_comp(0, m): print('yes') else: print('no')
s230929022
p02271
u605879293
1525333114
Python
Python3
py
Runtime Error
7740
5616
384
global n n = int(input()) a_array = [int(x) for x in input().split()] q = int(input()) m_array = [int(x) for x in input().split()] def solve(a, m): if m == 0: return True if a >= n: return False res = solve(a + 1, m) or solve(a + 1, m - a_array[a]) return res for m in m_array: if solve(0, m): print("yes") else: print("no")
s486965421
p02271
u255317651
1525342375
Python
Python3
py
Runtime Error
0
0
921
# -*- coding: utf-8 -*- """ Created on Wed May 2 21:28:06 2018 ALDS1_5a_r2 Time Limit Exceeded @author: maezawa """ n = int(input()) a = list(map(int, input().split())) q = int(input()) m_array = list(map(int, input().split())) can_c_array = [[None for _ in range(m)] for _ in range(n)] def can_comp(i, m): #i番目以降の数列をつかってmを作れるか? if m == 0: return True elif i == n: return False else: if can_c_array[i+1][m] == None: c1 = can_comp(i+1, m) can_c_array[i+1][m] = c1 else: c1 = can_c_array[i+1][m] if can_c_array[i+1][m-a[i]] == None: c2 = can_comp(i+1, m-a[i]) can_c_array[i+1][m-a[i]] = c2 else: c2 = can_c_array[i+1][m-a[i]] return c1 or c2 for m in m_array: if can_comp(0, m): print('yes') else: print('no')