Problem:


Score : 100 points

Problem Statement

There is a set A = \{ a_1, a_2, \ldots, a_N \} consisting of N positive integers.
Taro and Jiro will play the following game against each other.

Initially, we have a pile consisting of K stones.
The two players perform the following operation alternately, starting from Taro:

Choose an element x in A, and remove exactly x stones from the pile.

A player loses when he becomes unable to play.
Assuming that both players play optimally, determine the winner.

Constraints

All values in input are integers.

1 \leq N \leq 100

1 \leq K \leq 10^5

1 \leq a_1 < a_2 < \cdots < a_N \leq K

Input

Input is given from Standard Input in the following format:

N K
a_1 a_2 \ldots a_N

Output

If Taro will win, print First; if Jiro will win, print Second.

Sample Input 1

2 4
2 3

Sample Output 1

First

If Taro removes three stones, Jiro cannot make a move.
Thus, Taro wins.

Sample Input 2

2 5
2 3

Sample Output 2

Second

Whatever Taro does in his operation, Jiro wins, as follows:

If Taro removes two stones, Jiro can remove three stones to make Taro unable to make a move.

If Taro removes three stones, Jiro can remove two stones to make Taro unable to make a move.

Sample Input 3

2 7
2 3

Sample Output 3

First

Taro should remove two stones. Then, whatever Jiro does in his operation, Taro wins, as follows:

If Jiro removes two stones, Taro can remove three stones to make Jiro unable to make a move.

If Jiro removes three stones, Taro can remove two stones to make Jiro unable to make a move.

Sample Input 4

3 20
1 2 3

Sample Output 4

Second

Sample Input 5

3 21
1 2 3

Sample Output 5

First

Sample Input 6

1 100000
1

Sample Output 6

Second



Sample input:
2 4
2 3


Sample output:
First

Submission status: Accepted

Solution code:
import sys
# # import re
# import math
# import collections
# # import decimal
# import bisect
# import itertools
# import fractions
# # import functools
# import copy
# # import heapq
# import decimal
# # import statistics
# import queue

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

def main():
    n, k = ns()
    a = na()

    dp = [False] * (k + 1)

    for i in range(k + 1):
        for ai in a:
            if i + ai < k + 1:
                dp[i + ai] |= not dp[i]
            else:
                break

    print("First" if dp[k] else "Second")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

def main():
    n, k = ns()
    a = na()

    dp = [False] * (k + 1)

    for i in range(k + 1):
        for ai in a:
            if i + ai < k + 1:
                dp[i + ai] |= not dp[i]
            else:
                break

    print("First" if dp[k] else "Second")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

def main():
    n, k = ns()
    a = na()

    dp = [False] * (k + 1)

    for i in range(k + 1):
        for ai in a:
            if i + ai < k + 1:
                dp[i + ai] |= not dp[i]

    print("First" if dp[k] else "Second")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

def main():
    n, k = ns()
    a = na()

    dp = [False for _ in range(k + 1)]

    for i in range(k + 1):
        for ai in a:
            if i + ai < k + 1:
                dp[i + ai] |= not dp[i]

    print("First" if dp[k] else "Second")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n, k = map(int,input().split())
A = list(map(int,input().split()))

D = [0] * (k+1)
for i in range(k+1):
    safe = 0
    for j in range(n):
        if i-A[j] >= 0 and D[i-A[j]] == 0:
            safe = 1
    D[i] = safe

print("First" if D[-1]==1 else "Second")

Submission status: Accepted

Solution code:

def resolve():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    dp = [False]*(K+1)
        
    for i in range(K+1):
        for j in range(N):
            if i - A[j] >= 0:
                dp[i] |= not dp[i-A[j]]
    if dp[K]:
        print("First")
    else:
        print("Second")


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:

def resolve():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    dp = [False]*(K+1)

    for i in range(K+1):
        for j in range(N):
            if i - A[j] >= 0:
                dp[i] |= ~dp[i-A[j]]
    if dp[K]:
        print("First")
    else:
        print("Second")


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
dp=[False]*(k+1)
for i in range(1,k+1):
  for j in range(n):
    if  i-a[j]<0:
      break
    if dp[i-a[j]]==False:
      dp[i]=True
if dp[k]==True:
  print('First')
else:
  print('Second')

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**7)
n, stones = map(int, readline().split())
a = list(map(int,readline().split()))
dp = [-1]*stones
def can_or_cant(rem, chance):
    if rem == 0:
        return True
    if dp[rem] != -1:
        return dp[rem]
    den = 2 if chance == 1 else 2
    for j in range(len(a)):
        if rem - a[j] >= 0 and can_or_cant(rem-a[j], den):
            dp[rem] = False
            return False
    dp[rem] = True
    return True


res = False
for i in range(n):
    if can_or_cant(stones - a[i], 1):
        res = True
        break
print("First" if res else "Second")

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
dp = [0] * (k + 1)
for i in range(k):
    if dp[i] == 0:
        for ai in a:
            if i + ai > k:
                break
            dp[i+ai] = 1
print('First' if dp[k] else 'Second')

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
a_list = list(map(int, input().split()))

dp = [False] * (K+1)
for i in range(1, K+1):
    for a in a_list:
        if i >= a:
            dp[i] = dp[i] or ~dp[i-a]
if dp[K]:
    print('First')
else:
    print('Second')

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N, K = map(int, readline().split())
    A = list(map(int, readline().split()))
    dp = [False] * (K+1)

    for i in range(0,K+1):
        for a in A:
            if i - a >= 0:
                # 遷移先に一つでもFalseがあれば遷移元dp[i]を勝ち(True)にできる
                # 遷移先が全てTrueであれば、勝つことはできないので遷移元dp[i]はFalseになる
                dp[i] = dp[i] or (not dp[i-a])

    if dp[K]:
        print('First')
    else:
        print('Second')




if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
def main():
    N,K=tuple(map(int,sys.stdin.readline().split()))
    a=tuple(map(int,sys.stdin.readline().split()))
    dp=[False for _ in range(K+1)]
    for i in range(K+1):
        for x in a:
            if i-x>=0:dp[i]=dp[i] or (not dp[i-x])
    print('First') if dp[K] is True else print('Second')
if __name__=='__main__':main()

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    n,k = (int(x) for x in input().split())
    choice = [int(x) for x in input().split()]

    #print(n,k,choice)

    win = [False] * (k+1)
    for i in range(k+1):
        for x in choice:
            if i-x>=0 and not win[i-x]:
                win[i] = True
                break

    print("First" if win[k] else "Second")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

#from collections import defaultdict
#from heapq import heappush, heappop
import sys

sys.setrecursionlimit(10**6)
input = sys.stdin.buffer.readline
INF = 10 ** 9 + 1  # sys.maxsize # float("inf")


def debug(*x):
    print(*x, file=sys.stderr)


def solve(N, K, AS):
    AS.sort()
    MIN = AS[0]

    table = [0] * (K + 1)
    for i in range(MIN):
        table[i] = -1  # LOSE

    for i in range(MIN, K + 1):
        for a in AS:
            if table[i - a] == -1:
                table[i] = 1
                break
        else:
            table[i] = -1

    # debug(": table", table)

    if table[K] == 1:
        return "First"

    else:
        return "Second"


def main():
    # parse input
    N, K = map(int, input().split())
    AS = list(map(int, input().split()))
    print(solve(N, K, AS))


# tests
T1 = """
2 4
2 3
"""


def test_T1():
    """
    >>> as_input(T1)
    >>> main()
    First
    """


T2 = """
2 5
2 3
"""


def test_T2():
    """
    >>> as_input(T2)
    >>> main()
    Second
    """


T3 = """
2 7
2 3
"""


def test_T3():
    """
    >>> as_input(T3)
    >>> main()
    First
    """


T4 = """
3 20
1 2 3
"""


def test_T4():
    """
    >>> as_input(T4)
    >>> main()
    Second
    """


T5 = """
3 21
1 2 3
"""


def test_T5():
    """
    >>> as_input(T5)
    >>> main()
    First
    """


T6 = """
1 100000
1
"""


def test_T6():
    """
    >>> as_input(T6)
    >>> main()
    Second
    """
# add tests above


def _test():
    import doctest
    doctest.testmod()


def as_input(s):
    "use in test, use given string as input file"
    import io
    global read, input
    f = io.StringIO(s.strip())

    def input():
        return bytes(f.readline(), "ascii")

    def read():
        return bytes(f.read(), "ascii")


USE_NUMBA = False
if (USE_NUMBA and sys.argv[-1] == 'ONLINE_JUDGE') or sys.argv[-1] == '-c':
    print("compiling")
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('solve', solve.__doc__.strip().split()[0])(solve)
    cc.compile()
    exit()
else:
    input = sys.stdin.buffer.readline
    read = sys.stdin.buffer.read

    if (USE_NUMBA and sys.argv[-1] != '-p') or sys.argv[-1] == "--numba":
        # -p: pure python mode
        # if not -p, import compiled module
        from my_module import solve  # pylint: disable=all
    elif sys.argv[-1] == "-t":
        print("testing")
        _test()
        sys.exit()
    elif sys.argv[-1] != '-p' and len(sys.argv) == 2:
        # input given as file
        input_as_file = open(sys.argv[1])
        input = input_as_file.buffer.readline
        read = input_as_file.buffer.read

    main()

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
import bisect


# from collections import deque


# map(int, sys.stdin.read().split())


def input():
    return sys.stdin.readline().rstrip()


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    dp = [False] * (K + 1)
    dp[0] = False  # 後手の勝ち
    for i in range(K + 1):
        for j in A:
            if j <= i and dp[i-j]==False:
                dp[i] = True
                break
    if dp[K]:
        print("First")
    else:
        print("Second")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
dp = [False for _ in range(K+1)]
for i in range(1, K+1):
    for j in a:
        if i - j >= 0:
            dp[i] = dp[i] or not dp[i - j]
        else:
            break
if dp[-1]:
    print("First")
else:
    print("Second")

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


def naa(N): return [na() for _ in range(N)]


def ns(): return stdin.readline().rstrip()  # ignore trailing spaces


N, K = na()
a_array = na()

win = [0] * (K+1)

for i in range(a_array[0]):
    win[i] = 1

for i in range(a_array[0], K+1):
    for a in a_array:
        if i-a >= 0 and win[i-a] == 1:
            win[i] = -1
            break
    else:
        win[i] = 1

# print(win)

print("First" if win[-1] == -1 else "Second")

Submission status: Accepted

Solution code:
###==================================================
### import
#import bisect
#from collections import Counter, deque, defaultdict
#from copy import deepcopy
#from functools import reduce, lru_cache
#from heapq import heappush, heappop
#import itertools
#import math
#import string
import sys
### stdin
def input(): return sys.stdin.readline()
def iIn(): return int(input())
def iInM(): return map(int, input().split())
def iInM1(): return map(int1, input().split())
def iInLH(): return list(map(int, input().split()))
def iInLH1(): return list(map(int1, input().split()))
def iInLV(n): return [iIn() for _ in range(n)]
def iInLV1(n): return [iIn()-1 for _ in range(n)]
def iInLD(n): return [iInLH() for _ in range(n)]
def iInLD1(n): return [iInLH1() for _ in range(n)]
def sInLH(): return list(input().split())
def sInLV(n): return [input().rstrip('\n') for _ in range(n)]
def sInLD(n): return [sInLH() for _ in range(n)]
### stdout
def OutH(lst, deli=' '): print(deli.join(map(str, lst)))
def OutV(lst): print('\n'.join(map(str, lst)))
### setting
sys.setrecursionlimit(10 ** 6)
### utils
int1 = lambda x: int(x) - 1
### constants
INF = int(1e9)
MOD = 1000000007
dx = (-1, 0, 1, 0)
dy = (0, -1, 0, 1)
###---------------------------------------------------

N, K = iInM()
A = iInLH()

dp = [0] * (K + 1) 
# 0: lose
# 1: win

for i in range(1, K + 1):
    for j in range(N):
        if i - A[j] < 0:
            break
        if dp[i - A[j]] == 0:
            dp[i] = 1
            break

ans = 'First' if dp[K] else 'Second'
print(ans)

#print(dp)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
dp=[0]*(k+1)
for i in range(k+1):
  for j in range(n):
    if i-a[j]>=0:
      if dp[i-a[j]]==0:
        dp[i]=1
        break
if dp[k]:print('First')
else:print('Second')

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
# 復元プール
a = list(map(int, input().split()))
dp = [False for _ in range(K+1)]
# dp[i]石が残りi個のとき、先手が勝てるか
for i in range(1, K+1):
    for j in range(N):
        if i - a[j] >= 0:
            dp[i] = dp[i] or (not dp[i - a[j]])
if dp[K]:
    print("First")
else:
    print("Second")

Submission status: Accepted

Solution code:
def solve(a,k):
    dp=[0]*(k+1)
    for i in range(k+1):
        for j in a:
            if i>=j and not dp[i-j]:
                dp[i]=1
    return 'First' if dp[-1] else 'Second'
if __name__=='__main__':
    n,k=map(int,input().split())
    a=list(map(int,input().split()))
    print(solve(a,k))

Submission status: Accepted

Solution code:
n, k = list(map(int, input().split()))

arr = list(map(int, input().split()))

dp = [1] * (k+1)


for i in range(1, k+1):
    curr = 1
    for j in range(len(arr)):
        if arr[j] <= i:
            if dp[i-arr[j]] == 0:
                curr = 1
            else:
                curr = 0
                break
    
    dp[i] = curr

# print(dp)

if dp[-1] == 1:
    print("Second")
else:
    print("First")

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
lst = list(map(int, input().split()))

dp = [0] * (k+1) #dp[i]は石の数が残りi個のときに手番プレイヤーが勝利できるか

for i in range(1, k+1):
    flg = 0
    for j in lst:
        if i - j >= 0:
            if not dp[i-j]: #一度でも0(False)があればflg1(True)
                flg = 1
                break
    if flg:
        dp[i] = 1
            
if dp[k]:
    print('First')
else:
    print('Second')

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))

dp = [False]*(k+1)

for i in range(k+1):
    flag = 0
    for j in a:
        if i-j < 0:
            continue
        if not dp[i-j]:
            flag = 1
            break

    if flag:
        dp[i] = True

if dp[k]:
    print("First")
else:
    print("Second")

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")



n,k = map(int, input().split())
a = list(map(int, input().split()))

dp = [None]*(k+1)
dp[0] = 0
for i in range(1,k+1):
    s = set(range(n+1))
    for j in range(n):
        if i-a[j]>=0:
            s.discard(dp[i-a[j]])
    dp[i] = min(s)
if dp[k]==0:
    ans = "Second"
else:
    ans = "First"
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
a = list(map(int, input().split()))

dp = [-1] * (K+1)
dp[0] = 1
for i in range(1, K+1):
    l = [dp[i-aj] if i-aj>=0 else 0 for aj in a]
    dp[i] = 0 if 1 in l else 1
        
ans = 'First' if dp[-1] == 0 else 'Second'
print(ans)

Submission status: Accepted

Solution code:
######################################################
############Created by Devesh Kumar###################
#############devesh1102@gmail.com####################
##########For CodeForces(Devesh1102)#################
#####################2020#############################
######################################################
import sys
input = sys.stdin.readline

# import sys
import heapq 
import copy
import math
import decimal
# import sys.stdout.flush as flush
# from decimal import *
#heapq.heapify(li) 
#
#heapq.heappush(li,4) 
#
#heapq.heappop(li)
#
# &	Bitwise AND Operator	10 & 7 = 2
# |	Bitwise OR Operator	10 | 7 = 15
# ^	Bitwise XOR Operator	10 ^ 7 = 13
 
# <<	Bitwise Left Shift operator	10<<2 = 40
# >>	Bitwise Right Shift Operator
# '''############ ---- Input Functions ---- #######Start#####'''
 

def inp():
	return(int(input()))
def inlt(): 
	return(list(map(int,input().split())))
def insr():
	s = input()
	return(list(s[:len(s) - 1]))
def insr2():
	s = input()
	return((s[:len(s) - 1]))
def invr():
	return(map(int,input().split()))
 ############ ---- Input Functions ---- #######End
 # #####   

def pr_list(a):
	print(*a, sep=" ")
def main():
	# tests =  inp()
	tests = 1
	mod = 1000000007
	limit = 10**18
	ans = 0
	start = {}
	for test in range(tests):
		[n,k] = inlt()
		a = inlt()
		dp = [0 for i in range(k+1)]
		for i in range(k+1):
			flag = 0
			for j in a:
				if i-j<0:
					break
				if dp[i-j] == 0:
					flag = 1
					break
			dp[i] = flag
		if dp[k] == 1:
			print("First")
		else :
			print("Second")
				





		
		


if __name__== "__main__":
	main()

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
*a,= map(int,input().split())
a=sorted(a)
limit=10**5+5
dp=[False]*limit

for i in range(limit):
    if dp[i]==False:
        for j in range(n):
            if i+a[j]<limit:
                dp[i+a[j]]=True
if dp[k]:
    print('First')
else:
    print('Second')

Submission status: Accepted

Solution code:
import sys
import math
from  collections import defaultdict

# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')


def solve(test):
	n, k = map(int, input().split())
	a = list(map(int, input().split()))


	dp = [None for i in range(k + 1)]
	dp[0] = False
	for j in range(1, k + 1):
		dp[j] = False
		for i in range(n):
			if j >= a[i]:
				dp[j] = not dp[j - a[i]]
				if dp[j]:
					break

	print('First' if dp[k] else 'Second')

if __name__ == "__main__":
	test_cases = 1
	for t in range(1, test_cases + 1):
		solve(t)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
 
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
 
dp = [0 for i in range(K+1)]
for i in range(K+1):
    if not dp[i]:
        for j in range(N):
            if i + A[j] < K + 1:
                dp[i+A[j]] = 1
 
if dp[K]: print("First")
else: print("Second")

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
dp = [False]*(k+1)
for i in range(1,k+1):
    for j in range(n):
        if i-a[j]<0:
            break
        if dp[i-a[j]]==False:
            dp[i] = True
            break
if dp[k]==True:
    print("First")
else:
    print("Second")

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
arr=list(map(int,input().split()))
arr.sort()
dp=[-1]*(k+1)

for i in range(1,k+1):
    m=1
    for j in arr:
        if(i>=j):
            m = min(dp[i-j],m)
    dp[i] = -1*m

if(dp[k]==1):
    print("First")
else:
    print("Second")

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
arr=[int(i) for i in input().split()]
dp=[0 for i in range(k+1)]
for i in range(1,k+1):
    for j in range(n):
        if arr[j]<=i and dp[i-arr[j]]==0:
            dp[i]=1
if dp[k]==1:
    print("First")
else:
    print("Second")

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
a = tuple(map(int, input().split()))

#dp[i] := 残りがi個の時に手番が回ってきた方の勝敗
#0: 負け,
#1: 勝ち
#当然残り0個は負け
dp = [0] * (k+1)
#aの要素だけ残っている時，それを全てとってしまい，相手に0を渡すことができるので，1になる
for i in a:
    dp[i] = 1

#数字が小さい方からチェックしていき，aのいずれかの要素だけ小さくなったとき勝ちなら勝ち
#そうでなければ負け
for i in range(1, k+1):
    for e in a:
        #まず取れないとダメ
        if i > e:
            #その上で遷移後の状態を調べる
            if not dp[i-e]:
                dp[i] = 1

if dp[k]:
    print("First")
else:
    print("Second")

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

N, K = map(int, input().split())
A = [int(i) for i in input().split()]

dp = [0 for i in range(K+1)]
for i in range(K+1):
    if not dp[i]:
        for j in range(N):
            if i + A[j] < K + 1:
                dp[i+A[j]] = 1

if dp[K]: print("First")
else: print("Second")

Submission status: Accepted

Solution code:
def solve():
    N, K = map(int, input().split())
    As = list(map(int, input().split()))

    WLs = [0] * (K+1)
    for x in range(1, K+1):
        for A in As:
            if x-A < 0:
                break
            if WLs[x-A] == 0:
                WLs[x] = 1
                break

    if WLs[K]:
        print('First')
    else:
        print('Second')


solve()

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
dp=[0]*(k+1)
dp[0]=0

for i in range(1,k+1):
    z=0
    for j in range(n):
        if i-a[j]>=0:
            if z==0:
                dp[i]=1
            dp[i]= dp[i] and dp[i-a[j]]
            z=1
    if z:
        dp[i]=(dp[i]+1)%2

print("First" if dp[k] else "Second")

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
arr = list(map(int, input().split()))
dp = [False]*(K+1)
for i in range(K+1):
    for k in range(N):
        if i >= arr[k] and not dp[i-arr[k]]:
            dp[i] = True
print('First' if dp[K] else 'Second')

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
#dp[k] 0 => lose of turn player 1 => win of turn player
dp = [-1 for i in range(K+1)]
for i in range(min(A)):
    dp[i] = 0
for k in range(1,K+1):
    if dp[k] > 0:
        continue
    if all(dp[k-a] == 1 for a in A if k - a >= 0): #どんな減らし方をしても手番が負け
        dp[k] = 0
    else:
        dp[k] = 1
print(['Second', 'First'][dp[-1]])

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
stone = list(map(int, input().split()))
dp = [False]*(K+1)
for i in range(1,K+1):
    for k in range(N):
        if i >= stone[k]:
            if not dp[i-stone[k]]:
                dp[i] = True
print('First' if dp[K] else 'Second')

Submission status: Accepted

Solution code:
def main():
    N, K = list(map(int, input().split(' ')))
    A = list(map(int, input().split(' ')))
    dp = [0 for _ in range(K + 1)]  # whether Taro wins
    for n in range(1, K + 1):
        win = 0
        for a in A:
            if n - a >= 0 and dp[n - a] == 0:
                win = 1
                break
        dp[n] = win
    print('First' if dp[K] == 1 else 'Second')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
li=[int(k) for k in input().split()]
dp=[False]*(k+1)
for i in range(1,k+1):
  for j in range(len(li)):
    if i-li[j]<0:
      continue
    if dp[i-li[j]]==False:
      dp[i]=True
      break
if dp[k]==True:
  print("First")
else:
  print("Second")

Submission status: Accepted

Solution code:
def is_win(n,k):
	dp=[False]*(k+1)
	for i in range(k+1):
		for j in range(n):
			if i-arr[j]>=0 and dp[i-arr[j]]==False:
				dp[i]=True
				break

	return dp[k]
	

# with open ('input.txt') as f :
n,k=map(int,input().split())
arr=list(map(int,input().split()))
res=is_win(n,k)
print('First' if res else 'Second')

# 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99

Submission status: Accepted

Solution code:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,k=LI()
  l=LI()

  dp=[0]*100100

  for i in range(k):
    for x in l:
      y=dp[i]

      if y==0 and i+x<100100:
        dp[i+x]=1

  if dp[k]==1:
    return 'First'
  return 'Second'

# main()
print(main())

Submission status: Accepted

Solution code:
# dp[i] - True if first player has i stones and win

n, k = [int(x) for x in input().split()]

arr = [int(x) for x in input().split()]

dp = [False for _ in range(k+1)]

for i in range(k+1):
    for x in arr:
        if i-x >= 0 and not dp[i-x]:
            dp[i] = True

print("First" if dp[k] else "Second")

Submission status: Accepted

Solution code:
#dp[i]denotes who will win if i stones left
l=input().split()
n=int(l[0])
k=int(l[1])
l=input().split()
li=[int(i) for i in l]
hashi=dict()
for i in li:
	hashi[i]=1
m=min(li)
dp=[0 for i in range(k+1)]
dp[0]=2
for i in range(1,k+1):
	if(i<m):
		dp[i]=2
	done=0
	for j in hashi:
		if(i>=j and dp[i-j]==2):
			done=1
			break
	dp[i]=2-done
if(dp[k]==1):
	print("First")
else:
	print("Second")

Submission status: Accepted

Solution code:


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    """
    OPT[K] - answers if Taro wins with K stones

    OPT[a[i]] = True 1 <= k <= N

    5
    2 3
    
    t t j j j
    t t t j j

    OPT(K) - True, if Taro loses the game with K stones
    OPT(K) = all(not OPT(K-a[i])) 1 <= i <= N
    OPT(0) = True
    """
    N, K = read_ints()
    a = read_ints()
    OPT = [False]*(K+1)
    OPT[0] = True
    for k in range(1, K+1):
        OPT[k] = all(not OPT[k-a[i]] for i in range(N) if k-a[i] >= 0)
    if OPT[K]:
        return 'Second'
    return 'First'


if __name__ == '__main__':
    print(solve())

Submission status: Accepted

Solution code:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
# from math import gcd
from functools import lru_cache
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n,k=map(int,input().split())
a=list(map(int,input().split()))

lst=[0]*(k+1)
# for i in range(a[0]):
#     lst[i]=0
# print(lst)
# for i in range(a[0],a[-1]+1):
#     lst[i]=1
# print(lst)

for i in range(k+1):
    flag=1
    for j in range(n):
        if i-a[j]>=0:
            flag=min(flag,lst[i-a[j]])

    if flag==0:
        lst[i]=1
    else:
        lst[i]=0
# print(lst)
if lst[k]==1:
    print("First")
else:
    print("Second")

Submission status: Accepted

Solution code:
def main():
    N, K = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()
    dp = [False] * (K+1)
    for i in range(K+1):
        for hop in a:
            if i - hop >= 0:
                if dp[i - hop] is False:
                    dp[i] = True
                    break
    if dp[-1]:
        print("First")
    else:
        print("Second")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))

dp = [False]*(2*K + 1)
for i in range(K):
    if not dp[i]:
        for a in A:
            dp[i+a] = True
if dp[K]:
    print("First")
else:
    print("Second")

Submission status: Accepted

Solution code:



n, k = list(map(int, input().split()))

a = list(map(int, input().split()))


dp = [0]*(k + 1)

for i in range(1, k + 1):
    for move in a:
        if i - move >= 0:
            if dp[i - move] == 0:
                dp[i] = 1


if dp[i] == 1:
    print("First")

else:
    print("Second")

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
#for _ in range(int(input())):
#	n=int(input())
n,k=map(int,input().split())
#	s=input().strip()
a=list(map(int,input().split()))
dp=[False]*(k+1)
for i in range(1,k+1):
	for j in range(n):
		if i-a[j]>=0 and dp[i-a[j]]==False:
			dp[i]=True;break
if dp[-1]:print("First")
else:print("Second")

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))

dp = [1] * (k + 1)
player = ["First", "Second"]

for i in range(1, k + 1):
    for j in range(n):
        if 0 <= i - a[j] and dp[i - a[j]] == 1:
            dp[i] = 0

print(player[dp[k]])