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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
s845038590 | p04045 | u669770658 | 1542153512 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 301 | price, len_hate_set = map(int, input().split())
hate_set = set([int(i) for i in input().split()])
ans = 0
while True:
if all(map(lambda x: int(x) in set(range(0, 10)) - hate_set,
[int(str(ans)[i]) for i in range(len(str(ans)))])) and ans >= price:
print ans
ans += 1 |
s200630963 | p04045 | u943657163 | 1541272492 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3060 | 208 | n, k = input().split()
dic = [int(_) for _ in input().split()]
not_in = [i for i in range(10) if i not in dic]
ans = [min(list(filter(lambda x: int(i) <= x, not_in))) for i in n]
print(''.join(map(str, ans))) |
s614384793 | p04045 | u637824361 | 1540951263 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3060 | 253 | n, k = map(int, input().split())
d = [int(i) for i in input().split()]
for i in range(100000):
m = n + i
N = []
while(m > 0):
N.append(m%10)
m //= 10
N.reverse()
if N.intersection(d) == []:
print(N)
exit()
else:
continue |
s676841300 | p04045 | u459697504 | 1539926155 | Python | Python (3.4.3) | py | Runtime Error | 85 | 4120 | 870 | #! /usr/bin/python3
# こだわり者いろはちゃん / Iroha's Obsession
"""
1≦N<10000
1≦K<10
0≦D1<D2<…<DK≦9
{D1,D2,…,DK}≠{1,2,3,4,5,6,7,8,9}
"""
N, K = map(int, input().split())
D = list(map(int, input().split()))
test_mode = False
def check_num(x, d):
"""
金額xの中に中の文字があるか確認する関数。
x : 現在の金額(N, x+1 を想定)
d : 嫌いな数字のリスト(D を想定)
文字列 x にリスト d 中の要素が含まれているか、d の要素 num を順に確認し、
含まれていたら1円足して再試行する。
"""
if test_mode:
print('x =', x)
for num in d:
str_x = str(x)
str_num = str(num)
if str_num in str_x:
return check_num(x+1, d)
return x
amount = check_num(N, D)
print(amount)
|
s784693491 | p04045 | u459697504 | 1539925740 | Python | Python (3.4.3) | py | Runtime Error | 85 | 4120 | 976 | #! /usr/bin/python3
# こだわり者いろはちゃん / Iroha's Obsession
"""
1≦N<10000
1≦K<10
0≦D1<D2<…<DK≦9
{D1,D2,…,DK}≠{1,2,3,4,5,6,7,8,9}
"""
N, K = map(int, input().split())
D = list(map(int, input().split()))
test_mode = False
def check_num(x, d):
"""
金額xの中に中の文字があるか確認する関数。
x : 現在の金額(N, x+1 を想定)
d : 嫌いな数字のリスト(D を想定)
文字列 x にリスト d 中の要素が含まれているか、d の要素 num を順に確認し、
含まれていたら1円足して再試行する。
"""
if test_mode:
print('x =', x)
for num in d:
str_x = str(x)
str_num = str(num)
if str_num in str_x:
return check_num(x+1, d)
return x
def main():
"""
金額を算出して出力
"""
amount = check_num(N, D)
print(amount)
if __name__ == '__main__':
main()
|
s608883540 | p04045 | u459697504 | 1539925042 | Python | Python (3.4.3) | py | Runtime Error | 87 | 4124 | 1091 | #! /usr/bin/python3
# こだわり者いろはちゃん / Iroha's Obsession
"""
1≦N<10000
1≦K<10
0≦D1<D2<…<DK≦9
{D1,D2,…,DK}≠{1,2,3,4,5,6,7,8,9}
"""
N, K = map(int, input().split())
D = list(map(int, input().split()))
test_mode = False
def check_num(x, d, n):
"""
金額xの中に中の文字があるか確認する関数。
x : 現在の金額(N, x+n を想定)
d : 嫌いな数字のリスト(D を想定)
n : 元の金額(N を想定)
文字列 x にリスト d 中の要素が含まれているか、d の要素 num を順に確認し、
含まれていたら元の金額 n を足して再試行する。
"""
if test_mode:
print('x =', x)
for num in d:
if test_mode:
print('num =', num)
str_x = str(x)
str_num = str(num)
if str_num in str_x:
return check_num(x+n, d, n)
return x
def main():
"""
金額を算出して出力
"""
amount = check_num(N, D, N)
print(amount)
if __name__ == '__main__':
main()
|
s005737478 | p04045 | u883048396 | 1537482087 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3188 | 1810 | iN,iK = [int(x) for x in input().split()]
aD = [int(x) for x in input().split()]
aUnList = sorted([x for x in range(10) if x not in aD])
aUnList.sort()
sN = str(iN)
iF = int(sN[0])
def fCheckDigit(sTarget,iPoint,aUnList,aRet,bRev):
iL = len(sTarget)
iF = int(sTarget[iPoint])
aUpper = [x for x in aUnList if x >= iF]
aUpper.sort()
if bRev: #遡ってきたとき
#もうひとつ上があるかどうか
if len(aUpper) == 1 and aUpper[0] == iF: #==のとき。もうひとつ上はない
if iPoint == 0:
if aUnList[0] == 0:
return [str(aUnList[1])] + ["0"] * iL
else:
return [str(aUnList[0])] * iL
else:
return fCheckDigit(sTarget,iPoint -1 , aUnList,aRet,True)
else: #上の桁がある
if len(aUpper) == 1:
iNext = aUpper[0]
else:
iNext = aUpper[1]
return aRet[0:iPoint]+[str(iNext)]+[str(aUnList[0])]*(iL-1-iPoint)
else: #順向
if aUpper == []: #大きい数字がない
if iPoint == 0:
if aUnList[0] == 0:
return [str(aUnList[1])] + ["0"] * iL
else:
return [str(aUnList[0])]*(iL+1)
else:
return fCheckDigit(sTarget,iPoint+1,aUnList,aRet,False)
else:
if aUpper[0] != iF:
return aRet[0:iPoint]+[str(aUpper[0])] + [str(aUnList[0])]*(iL-1- iPoint)
else:
aRet.append(str(iF))
if iPoint < iL -1 :
return fCheckDigit(sTarget,iPoint+1,aUnList,aRet,False)
else:
return aRet
print( ''.join(fCheckDigit(sN,0,aUnList,[],False)))
|
s610435366 | p04045 | u883048396 | 1537481890 | Python | Python (3.4.3) | py | Runtime Error | 88 | 4276 | 1778 | iN,iK = [int(x) for x in input().split()]
aD = [int(x) for x in input().split()]
aUnList = sorted([x for x in range(10) if x not in aD])
sN = str(iN)
iF = int(sN[0])
def fCheckDigit(sTarget,iPoint,aUnList,aRet,bRev):
iL = len(sTarget)
iF = int(sTarget[iPoint])
aUpper = [x for x in aUnList if x >= iF]
if bRev: #遡ってきたとき
#もうひとつ上があるかどうか
if len(aUpper) == 1 and aUpper[0] == iF: #==のとき。もうひとつ上はない
if iPoint == 0:
if aUnList[0] == 0:
return [str(aUnList[1])] + ["0"] * iL
else:
return [str(aUnList[0])] * iL
else:
return fCheckDigit(sTarget,iPoint -1 , aUnList,aRet,True)
else: #上の桁がある
if len(aUpper) == 1:
iNext = aUpper[0]
else:
iNext = aUpper[1]
return aRet[0:iPoint]+[str(iNext)]+[str(aUnList[0])]*(iL-1-iPoint)
else: #順向
if aUpper == []: #大きい数字がない
if iPoint == 0:
if aUnList[0] == 0:
return [str(aUnList[1])] + ["0"] * iL
else:
return [str(aUnList[0])]*(iL+1)
else:
return fCheckDigit(sTarget,iPoint-1,aUnList,aRet,False)
else:
if aUpper[0] != iF:
return aRet[0:iPoint]+[str(aUpper[0])] + [str(aUnList[0])]*(iL-1- iPoint)
else:
aRet.append(str(iF))
if iPoint < iL -1 :
return fCheckDigit(sTarget,iPoint+1,aUnList,aRet,False)
else:
return aRet
print( ''.join(fCheckDigit(sN,0,aUnList,[],False)))
|
s734378322 | p04045 | u883048396 | 1537481524 | Python | Python (3.4.3) | py | Runtime Error | 85 | 4268 | 1665 | iN,iK = [int(x) for x in input().split()]
aD = [int(x) for x in input().split()]
aUnList = sorted([x for x in range(10) if x not in aD])
sN = str(iN)
iF = int(sN[0])
def fCheckDigit(sTarget,iPoint,aUnList,aRet,bRev):
iL = len(sTarget)
iF = int(sTarget[iPoint])
aUpper = [x for x in aUnList if x >= iF]
if bRev: #遡ってきたとき
#もうひとつ上があるかどうか
if len(aUpper) == 1 and aUpper[0] == iF : #==のとき。もうひとつ上はない
if iPoint == 0:
if aUnList[0] == 0:
return [str(aUnList[1])] + ["0"] * iL
else:
return [str(aUnList[0])] * iL
else:
return fCheckDigit(sTarget,iPoint -1 , aUnList,aRet,True)
else: #上の桁がある
return aRet[0:iPoint]+[str(aUpper[1])]+[str(aUnList[0])]*(iL-1-iPoint)
else: #順向
if aUpper == []: #大きい数字がない
if iPoint == 0:
if aUnList[0] == 0:
return [str(aUnList[1])] + ["0"] * iL
else:
return [str(aUnList[0])]*(iL+1)
else:
return fCheckDigit(sTarget,iPoint-1,aUnList,aRet,False)
else:
if aUpper[0] != iF:
return aRet[0:iPoint]+[str(aUpper[0])] + [str(aUnList[0])]*(iL-1- iPoint)
else:
aRet.append(str(iF))
if iPoint < iL -1 :
return fCheckDigit(sTarget,iPoint+1,aUnList,aRet,False)
else:
return aRet
print( ''.join(fCheckDigit(sN,0,aUnList,[],False)))
|
s413056807 | p04045 | u394853232 | 1536180309 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3060 | 231 | N , K = map(int,input().split())
lst = []
for i in range(K):
lst.append(input())
start = N
while True:
for num in str(start):
if num in lst:
break
else:
break
start += 1
print(str(start)) |
s795237012 | p04045 | u693048766 | 1535674924 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 357 | xs, k = input().split()
k = int(k)
xs = [int(x) for x in list(xs)]
ds = set([int(d) for d in input().split()])
#print(ds)
ans = []
for x in xs:
if x not in ds:
ans.append(x)
else:
us = [ u for u in range(0,10) if u not in ds ]
#print(us)
x = sorted([ p for p in us if p > x ]).pop(0)
ans.append(x)
print(''.join(map(str,ans))) |
s756688424 | p04045 | u807772568 | 1535506767 | Python | PyPy3 (2.4.0) | py | Runtime Error | 169 | 38256 | 164 | a,b = map(int,input().split())
c = input().split()
while 1:
f = 1
s = str(a)
for i in c:
if i in s: f = 0
if f : break
c += 1
print(c) |
s367454447 | p04045 | u807772568 | 1535506574 | Python | PyPy3 (2.4.0) | py | Runtime Error | 189 | 40432 | 164 | a,b = map(int,input().split())
c = input().split()
while 1:
f = 1
s = str(c)
for i in c:
if i in s: f = 0
if f : break
c += 1
print(c) |
s733606161 | p04045 | u807772568 | 1535506518 | Python | PyPy3 (2.4.0) | py | Runtime Error | 172 | 38640 | 164 | a,b = map(int,input().split())
c = input().split()
while 1:
f = 1
s = str(c)
for i in s:
if i in c: f = 0
if f : break
c += 1
print(c) |
s676600008 | p04045 | u807772568 | 1535506481 | Python | PyPy3 (2.4.0) | py | Runtime Error | 168 | 38256 | 164 | a,b = map(int,input().split())
c = input().split()
while 1:
f = 1
s = str(c)
for i in c:
if i in c: f = 0
if f : break
c += 1
print(c) |
s922400907 | p04045 | u599547273 | 1534611539 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 172 | n, k = map(int, input().split(" "))
d = input().split(" ")
for i in range(len(str(n))+1):
if str(n)[~i] not in d:
continue
while str(n)[~i] in d:
n += 10**i
print(n) |
s994723791 | p04045 | u599547273 | 1534611486 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 169 | n, k = map(int, input().split(" "))
d = input().split(" ")
for i in range(len(str(n))+1):
if str(n)[~i] not in d:
break
while str(n)[~i] in d:
n += 10**i
print(n) |
s946355450 | p04045 | u599547273 | 1534611405 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 136 | n, k = map(int, input().split(" "))
d = input().split(" ")
for i in range(len(str(n))+1):
while str(n)[~i] in d:
n += 10**i
print(n) |
s764495372 | p04045 | u693048766 | 1534019911 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 308 | N, K = map(int, input().split())
ds = [int(d) for d in input().split()]
us = [ i for i in range(10) if i not in ds]
#print(us)
oo = [int(s) for s in str(N)]
o_u = {}
for o in oo:
o_u[o] = min(list(filter(lambda x:x>=o, us)))
n = str(N)
for o, u in o_u.items():
n = n.replace(str(o),str(u))
print(n) |
s067092316 | p04045 | u572271833 | 1530949849 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 434 | N,K = map(int,input().split( ))
Ds = list(map(int,input().split( )))
word = list(map(int,list(str(N))))
z = 0
while z in Ds:
z += 1
for i in range(len(word)):
for j in range(len(Ds)):
if word[-i-1] in Ds:
word[-i-1] += 1
if i > 0:
word[-i:] = [z for i in range(i)]
if word[-i-1]>=10:
word[-i-2] += 1
word[-i-1:] += [z for i in range(i+1)]
s = list(map(str,word))
print(''.join(s)) |
s219275450 | p04045 | u572271833 | 1530949811 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 434 | N,K = map(int,input().split( ))
Ds = list(map(int,input().split( )))
word = list(map(int,list(str(N))))
z = 0
while z in Ds:
z += 1
for i in range(len(word)):
for j in range(len(Ds)):
if word[-i-1] in Ds:
word[-i-1] += 1
if i > 0:
word[-i:] = [z for i in range(i)]
if word[-i-1]>=10:
word[-i-2] += 1
word[-i-1:] += [z for i in range(i+1)]
s = list(map(str,word))
print(''.join(s)) |
s812863341 | p04045 | u470735879 | 1530892248 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 577 | n, k = map(int,input().split())
n = str(n)
unlike = list(map(int,input().split()))
like = []
ans = ''
for i in range(1, 10):
if i not in unlike:
like.append(i)
for num in range(len(n)):
for i in like:
if n[0] == 9 and (9 not in like):
ans += like[0]
break
if int(n[num]) <= i:
ans += str(i)
break
if len(ans) != (num + 1):
for j in like:
if int(ans[num - 1]) < j:
ans[num - 1] == j
break
if num == 0:
like.insert(0,0)
print(ans) |
s612952511 | p04045 | u118605645 | 1530787221 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 879 | n, k = (int(char) for char in input().split())
d = [int(i) for i in input().split()]
'''
n = 10
k = 8
d = [0, 2, 3]
D = [i for i in range(10)]
'''
like_vals = [int(str(i)) for i in D if i not in d]
i = 0
n = [int(str(n)[i]) for i in range(len(str(n)))]
r = [-1] * len(n)
while i < len(n):
if n[i] in like_vals:
r[i] = n[i]
i += 1
elif n[i] < max(like_vals):
like_bigger = [like_val for like_val in like_vals if like_val > n[i]]
r[i] = min(like_bigger)
for j in range(i + 1, len(n)):
r[j] = min(like_vals)
break
else:
r = [-1] * (len(n) + 1)
if min(like_vals) != 0:
r[0] = min(like_vals)
else:
r[0] = min([like_val for like_val in like_vals if like_val != 0])
for j in range(1, len(n) + 1):
r[j] = min(like_vals)
break
print(r) |
s511819129 | p04045 | u632557492 | 1530587753 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3060 | 424 | n, k = [i for i in input().split()]
d = [i for i in input().split()]
# OK 숫자의 집합을 구하고,
# 각 자리수부터 들어가 NG 숫자를 OK숫자로 바꿔주면 되는 거 아냐?
n = list(n)
ng = set(d)
for i in range(len(n)):
# print(ng)
ok = set([str(i) for i in range(10)]) - ng
# print(ok)
if i == 0:
ok.remove('0')
if n[i] in ng:
n[i] = str(min(ok))
print(''.join(n)) |
s489127000 | p04045 | u395086545 | 1530401332 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3060 | 230 | n, k = map(int, input().split())
d = list(map(int, input().split()))
for i in range(10*n+2):
if i >= n:
s = str(i)
for j in range(len(s)):
if int(s[j]) in d:
break
else:
print(i)
return 0
|
s418004815 | p04045 | u952708174 | 1525847900 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3060 | 426 | def c_iroha_obsession(N, K, D):
for ans in range(N, 10 * N + 1):
for digit in str(ans): # 1桁ずつ調べる
if int(digit) in D: # 嫌いな数字があった
break
else: # 嫌いな数字がなかった。このときのansが解
break
return ans
N,K = [int(i) for i in input().split()]
D = [int(i) for i in input().split()]
print(c_IrohaObsession(N, K, D)) |
s464018841 | p04045 | u125205981 | 1525335520 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 451 | def main():
N, K = map(int, input().split())
D = set(map(int, input().split()))
for i in range(10):
if i not in D:
min_ = i
break
ans = []
apnd = ans.append
num, i = N, 0
while num > 0:
while num % 10 in D:
num += 1
top = i
num, m = divmod(num, 10)
apnd(m)
i += 1
ans[0:top] = [min_] * top
print(*ans[::-1], sep='')
main()
|
s148335538 | p04045 | u709052417 | 1524982428 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 240 | N, K = map(int, input().split())
D = list(map(int, input().split()))
shiharai=N
l = [int(x) for x in list(str(N))]
for i in range(l):
while l[i] in D:
shiharai+=1
l = [int(x) for x in list(str(shiharai))]
print(shiharai) |
s411896493 | p04045 | u709052417 | 1524982386 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3060 | 240 | N, K = map(int, input().split())
D = list(map(int, input().split()))
shiharai=N
l = [int(x) for x in list(str(N))]
for i in range(l):
while l[i] in D:
shiharai+=1
l = [int(x) for x in list(str(shiharai))]
print(shiharai) |
s867128631 | p04045 | u231685196 | 1522087190 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 472 |
input_array = list(map(int,input().split()))
N = input_array[0]
input_array = list(map(int,input().split()))
num = [1,1,1,1,1,1,1,1,1,1]
ok = []
out = []
for l in range(len(input_array)):
num[input_array[l]] = 0
for i in range(len(num)):
if num[i] == 1:
ok.append(i)
N = list(str(N))
for n in N:
for m in ok:
if m >= int(n):
out.append(m)
break
for i in range(len(out)-1):
print(out[i],end="")
print(out[-1]) |
s119533351 | p04045 | u875478816 | 1521503575 | Python | Python (3.4.3) | py | Runtime Error | 412 | 3064 | 570 | li_1 = list(map(int,input().split()))
N = li_1[0]
K = li_1[1]
D = list(map(int,input().split()))
minvalue=N
temp=0
for i in range(10*N):
i=i+N
numtemp=i
num_4=int(i/10000)
i=i-10000*num_4
num_3=int(i/1000)
i=i-1000*num_3
num_2=int(i/100)
i=i-100*num_2
num_1=int(i/10)
i=i-10*num_1
num_0=i
for j in range(K):
if (num_0!=D[j])and(num_1!=D[j])and(num_2!=D[j])and(num_3!=D[j])and(num_4!=D[j]):
temp+=1
if temp==K:
num=numtemp
break
temp=0
print(num)
|
s074228576 | p04045 | u875478816 | 1521502381 | Python | Python (3.4.3) | py | Runtime Error | 41 | 3064 | 587 | li_1 = list(map(int,input().split()))
N = li_1[0]
K = li_1[1]
D = list(map(int,input().split()))
minvalue=N
temp=0
for i in range(10*(N+1)):
i=i+N
numtemp=i
num_4=int(i/10000)
i=i-10000*num_4
num_3=int(i/1000)
i=i-1000*num_3
num_2=int(i/100)
i=i-100*num_2
num_1=int(i/10)
i=i-10*num_1
num_0=i
for j in range(K):
if (num_0!=D[j])and(num_1!=D[j])and(num_2!=D[j])and(num_3!=D[j]):
if j==K-1:
temp=1
else:
break
if temp==1:
num=numtemp
break
print(num)
|
s511504712 | p04045 | u875478816 | 1521502230 | Python | Python (3.4.3) | py | Runtime Error | 38 | 3064 | 583 |
li_1 = list(map(int,input().split()))
N = li_1[0]
K = li_1[1]
D = list(map(int,input().split()))
minvalue=N
temp=0
for i in range(N+1):
i=i+N
numtemp=i
num_4=int(i/10000)
i=i-10000*num_4
num_3=int(i/1000)
i=i-1000*num_3
num_2=int(i/100)
i=i-100*num_2
num_1=int(i/10)
i=i-10*num_1
num_0=i
for j in range(K):
if (num_0!=D[j])and(num_1!=D[j])and(num_2!=D[j])and(num_3!=D[j]):
if j==K-1:
temp=1
else:
break
if temp==1:
num=numtemp
break
print(num)
|
s342694197 | p04045 | u143492911 | 1518148616 | Python | Python (3.4.3) | py | Runtime Error | 18 | 2940 | 205 | n,k=map(int,input().split())
d=list(input().split())
for i in range(n,100001):
set_i=set(list(str(i)))
for j in set_i:
if s in d:
break
else:
print(i)
break
|
s979709031 | p04045 | u055459962 | 1507957717 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 1088 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""042-c"""
import sys
ZERO_UNICODE = 48
def solve(dislike_digits_table, first_like_digit, number):
"""Solve."""
if dislike_digits_table[int(number[0])]:
while dislike_digits_table[int(number[0])]:
number = "{0}{1}".format(chr(ord(number[0]) + 1), number[1:])
number = number.replace(number[1:], first_like_digit * (len(number) - 1))
return number
def main():
"""Main function."""
dislike_digits_table = [False for _ in range(10)]
N, _ = sys.stdin.readline().split(' ')
digits = map(int, sys.stdin.readline().split(' '))
for digit in digits:
dislike_digits_table[digit] = True
first_like_digit = str(next(i for i, v
in enumerate(dislike_digits_table)
if not v))
for i, d in enumerate(N):
if dislike_digits_table[int(d)]:
N = N.replace(N[i:], solve(dislike_digits_table, first_like_digit, N[i:]))
break
print(N)
if __name__ == '__main__':
sys.exit(main()) |
s994011015 | p04045 | u650245944 | 1502277052 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 527 | N, K = map(int, input().split())
D = list(map(int, input().split()))
L = [i for i in range(10) if i not in D]
A = []
for i in L:
A.append(i)
for i in L:
for j in L:
A.append(10*i+j)
for i in L:
for j in L:
for k in L:
A.append(100*i+10*j+k)
for i in L:
for j in L:
for k in L:
for l in L:
A.append(1000*i+100*j+10*k+l)
for i in L:
for j in L:
for k in L:
for l in L:
for m in L:
A.append(10000*i+1000*j+100*k+10*l+m)
for i in A:
if i >= N:
print(i)
break |
s565426486 | p04045 | u788681441 | 1484260775 | Python | Python (3.4.3) | py | Runtime Error | 23 | 3064 | 383 | n, k = map(int, input().split())
dislikes = list(map(int, input().split())
m = n
while True:
m = list(str(m))
l = []
for p in m:
if int(p) not in dislikes:
l.append(p)
continue
else:
m = int(''.join(m))+1
break
if len(l) >= len(str(n)):
if int(''.join(l))>=n:
break
print(''.join(m)) |
s231547753 | p04045 | u122916923 | 1483919094 | Python | Python (3.4.3) | py | Runtime Error | 174 | 6476 | 1379 | N, K = [int(i) for i in input().split()]
ds = [int(i) for i in input().split()]
#N, K = (99999, 8)
#ds = [0,1,2,3,4,5,6,7,9]
def run_code(N, K, ds):
dislike_digits_set = set(i for i in ds)
avail_digits = [i for i in range(10) if i not in dislike_digits_set]
avail_min = avail_digits[0]
def get_next_digit(d):
last = 10
for ad in (avail_digits + [last]):
if ad >= d:
if ad == last:
return (1, avail_min)
else:
return (0, ad)
def to_num(n_digits):
num = 0
n = len(n_digits)
for i in range(n):
num += n_digits[i] * 10**(n-i-1)
return num
def to_digits(num):
return [int(i) for i in str(num)]
def search_nearest_larger(num):
n_digits = to_digits(num)
n = len(n_digits)
for i in range(n):
d_in = n_digits[i]
inc, d_out = get_next_digit(d_in)
if inc == 0 and d_in == d_out:
continue
if inc > 0:
num += 10**(n-i)
return search_nearest_larger(num)
else:
n_digits[i] = d_out
return to_num(n_digits[:i+1] + [avail_min]*(n-i-1))
return to_num(n_digits)
return search_nearest_larger(N)
res = run_code(N, K, ds)
print(res)
|
s219891551 | p04045 | u122916923 | 1483918251 | Python | Python (3.4.3) | py | Runtime Error | 23 | 3064 | 1050 | N, K = [int(i) for i in input().split()]
ds = [int(i) for i in input().split()]
#N, K = (99999, 1)
#ds = [0]
def run_code(N, K, ds):
dislike_digits_set = set(i for i in ds)
avail_digits = [i for i in range(10) if i not in dislike_digits_set]
avail_min = avail_digits[0]
def get_next_digit(d):
last = [10]
for ad in (avail_digits + last):
if ad >= d:
if ad == last:
return (1, avail_min)
else:
return (0, ad)
def to_num(n_digits):
num = 0
n = len(n_digits)
for i in range(n):
num += n_digits[i] * 10**(n-i-1)
return num
def to_digits(num):
return [int(i) for i in str(num)]
def search_nearest_larger(num):
n_digits = to_digits(num)
n = len(n_digits)
for i in range(n):
d_in = n_digits[i]
inc, d_out = get_next_digit(d_in)
if inc == 0 and d_in == d_out:
continue
if inc > 0:
|
s837836376 | p04045 | u831695469 | 1479018139 | Python | Python (3.4.3) | py | Runtime Error | 22 | 3064 | 198 | N, K = map(int, input().split())
D = list(map(int, input().split()))
n = str(N)
ans = N
for i in reversed(range(str(len(N)))):
temp = n[i]
while(int(temp) in D):
ans += 1
print(ans)
|
s762676909 | p04045 | u831695469 | 1479018017 | Python | Python (3.4.3) | py | Runtime Error | 22 | 3064 | 188 | N, K = map(int, input().split())
D = list(map(int, input().split()))
n = str(N)
ans = N
for i in reversed(range(N)):
temp = n[i]
while(int(temp) in D):
ans += 1
print(ans)
|
s815140573 | p04045 | u025504404 | 1478522190 | Python | Python (3.4.3) | py | Runtime Error | 23 | 3064 | 781 | n, k = [int(i) for i in input().split()]
q = n
not_liked = [int(i) for i in input().split()]
liked = [i for i in range(10) if i not in not_liked]
digits = list()
while(n):
digits.append(n%10)
n //= 10
digits.reverse()
ind = -2
for i in digits:
if i not in liked:
ind = digits.index(i)
break
js = list()
jss = list()
for i in digits:
for j in liked:
if j >= i:
js.append(j)
jss.append(js[:])
js.clear()
m = 0
number = str()
flag = True
for i in range(len(digits)):
if m != ind+1:
number += str(min(jss[i]))
m += 1
else:
k = len(str(q)) - m
val = int(number + str(min(liked))*k)
if val <= 10000:
print(val)
else:
print(10000)
flag = False
break
if flag:
val1 = int(number)
if val1 <= 10000:
print(val1)
else:
print(10000) |
s806999533 | p04045 | u025504404 | 1478521885 | Python | Python (3.4.3) | py | Runtime Error | 24 | 3192 | 758 | n, k = [int(i) for i in input().split()]
q = n
not_liked = [int(i) for i in input().split()]
liked = [i for i in range(10) if i not in not_liked]
digits = list()
while(n):
digits.append(n%10)
n //= 10
digits.reverse()
ind = -2
for i in digits:
if i not in liked:
ind = digits.index(i)
break
js = list()
jss = list()
for i in digits:
for j in liked:
if j >= i:
js.append(j)
jss.append(js[:])
js = []
m = 0
number = str()
flag = True
for i in jss:
if m != ind+1:
number += str(min(i))
m += 1
else:
k = len(str(q)) - m
val = int(number + str(min(liked))*k)
if val <= 10000:
print(val)
else:
print(10000)
flag = False
break
if flag:
val1 = int(number)
if val1 <= 10000:
print(val1)
else:
print(10000) |
s929331940 | p04045 | u025504404 | 1478521806 | Python | Python (3.4.3) | py | Runtime Error | 23 | 3192 | 780 | n, k = [int(i) for i in input().strip(" ").split()]
q = n
not_liked = [int(i) for i in input().strip(" ").split()]
liked = [i for i in range(10) if i not in not_liked]
digits = list()
while(n):
digits.append(n%10)
n //= 10
digits.reverse()
ind = -2
for i in digits:
if i not in liked:
ind = digits.index(i)
break
js = list()
jss = list()
for i in digits:
for j in liked:
if j >= i:
js.append(j)
jss.append(js[:])
js = []
m = 0
number = str()
flag = True
for i in jss:
if m != ind+1:
number += str(min(i))
m += 1
else:
k = len(str(q)) - m
val = int(number + str(min(liked))*k)
if val <= 10000:
print(val)
else:
print(10000)
flag = False
break
if flag:
val1 = int(number)
if val1 <= 10000:
print(val1)
else:
print(10000) |
s402522954 | p04045 | u025504404 | 1478520730 | Python | Python (3.4.3) | py | Runtime Error | 24 | 3064 | 669 | n, k = [int(i) for i in input().strip(" ").split()]
q = n
not_liked = [int(i) for i in input().strip(" ").split()]
liked = [i for i in range(10) if i not in not_liked]
digits = list()
while(n):
digits.append(n%10)
n //= 10
digits.reverse()
ind = -2
for i in digits:
if i not in liked:
ind = digits.index(i)
break
js = list()
jss = list()
for i in digits:
for j in liked:
if j >= i:
js.append(j)
jss.append(js[:])
js = []
m = 0
number = str()
flag = True
for i in jss:
if m != ind+1:
number += str(min(i))
m += 1
else:
k = len(str(q)) - m
print(int(number + str(min(liked))*k))
flag = False
break
if flag:
print(int(number)) |
s839492722 | p04045 | u117095520 | 1477685560 | Python | Python (2.7.6) | py | Runtime Error | 48 | 3524 | 420 | N, K = raw_input().split()
D = raw_input().split()
candi = [str(i) for i in xrange(10)]
for d in D:
candi.remove(d)
def decide(i):
if i >= len(N):
return ''
for c in candi:
if N[i] == c:
return c + decide(i+1)
elif N[i] < c:
return c + candi[0] * (len(N) - i - 1)
else:
return (candi[0] if candi[0] != 0 else candi[1]) + decide(i)
print decide(0) |
s036894632 | p04045 | u564917060 | 1469695128 | Python | Python (3.4.3) | py | Runtime Error | 50 | 4340 | 394 | import itertools
if __name__ == "__main__":
line_one = input().split()
line_two = input().split()
use_num = {'0','1','2','3','4','5','6','7','8','9'}.difference(line_two)
all_comb = list(itertools.product(use_num, repeat=len(str(line_one[0]))))
nums = list((map(int,["".join(x) for x in all_comb])))
ans = min([x for x in nums if x >= int(line_one[0])])
print(ans) |
s447764636 | p04045 | u557523358 | 1469329948 | Python | Python (3.4.3) | py | Runtime Error | 38 | 3064 | 516 | #include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <utility>
#include <vector>
int main() {
int n, k, d;
bool is_safe[10] = {};
std::cin >> n >> k;
std::fill(is_safe, is_safe + 10, true);
for (int ki = 0 ; ki < k; ++ki) {
std::cin >> d;
is_safe[d] = false;
}
while (true) {
int r = n;
while (r > 0) {
if (not is_safe[r % 10]) {
goto fail;
}
r /= 10;
}
std::cout << n << std::endl;
return 0;
fail:
++n;
}
} |
s006728586 | p04045 | u124139453 | 1469324493 | Python | Python (2.7.6) | py | Runtime Error | 225 | 2568 | 285 | n, k = map(int, raw_input().split())
d = map(int, raw_input().split())
def use_d(n):
for i in list(str(n)):
if int(i) in d:
return True
else:
return False
while n < 100000:
if use_d(n):
n += 1
else:
print n
sys.exit() |
s316420238 | p04046 | u682467216 | 1600391636 | Python | PyPy3 (7.3.0) | py | Runtime Error | 93 | 74876 | 1429 | # coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
import copy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)
def lcm(a, b): return a * b / gcd(a, b)
# 1 2 3
# a, b, c = LI()
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
# a = I()
def I(): return int(sys.stdin.buffer.readline())
# abc def
# a, b = LS()
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
# a = S()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
# 2
# 1
# 2
# [1, 2]
def IR(n): return [I() for i in range(n)]
# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]
def LIR(n): return [LI() for i in range(n)]
# 2
# abc
# def
# [abc, def]
def SR(n): return [S() for i in range(n)]
# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]
def LSR(n): return [LS() for i in range(n)]
# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]
def SRL(n): return [list(S()) for i in range(n)]
n, k = LI()
d = LI()
limit = 11*n
while n < limit:
flg = 1
for x in list(str(n)):
if int(x) in d:
flg = 0
break
if flg:
print(n)
break
n += 1 |
s670718509 | p04046 | u049364987 | 1599733573 | Python | Python (3.8.2) | py | Runtime Error | 24 | 9232 | 656 | from sys import stdin, stdout
from time import perf_counter
import sys
sys.setrecursionlimit(10**9)
mod = 10**9+7
# import sys
# sys.stdout = open("e:/cp/output.txt","w")
# sys.stdin = open("e:/cp/input.txt","r")
n,k = map(int,input().split())
d= list(map(int,input().split()))
test = [1,2,3,4,5,6,7,8,9]
for item in range(k):
if d[item]==0:
print(n)
exit()
result =[]
for item in test:
if item not in d:
result.append(item)
n= list(str(n))
# final_result =[]
for item in range(len(n)):
if int(n[item])>0:
if n[item] != result[item]:
n[item] = str(result[item])
ans = "".join(n)
print(ans)
|
s282585295 | p04046 | u049364987 | 1599733506 | Python | Python (3.8.2) | py | Runtime Error | 30 | 9128 | 558 | from sys import stdin, stdout
from time import perf_counter
import sys
sys.setrecursionlimit(10**9)
mod = 10**9+7
n,k = map(int,input().split())
d= list(map(int,input().split()))
test = [1,2,3,4,5,6,7,8,9]
for item in range(k):
if d[item]==0:
print(n)
exit()
result =[]
for item in test:
if item not in d:
result.append(item)
n= list(str(n))
# final_result =[]
for item in range(len(n)):
if int(n[item])>0:
if n[item] != result[item]:
n[item] = str(result[item])
ans = "".join(n)
print(ans)
|
s611185518 | p04046 | u049364987 | 1599733485 | Python | Python (3.8.2) | py | Runtime Error | 23 | 9124 | 558 | from sys import stdin, stdout
from time import perf_counter
import sys
sys.setrecursionlimit(10**9)
mod = 10**9+7
n,k = map(int,input().split())
d= list(map(int,input().split()))
test = [1,2,3,4,5,6,7,8,9]
for item in range(k):
if d[item]==0:
print(n)
exit()
result =[]
for item in test:
if item not in d:
result.append(item)
n= list(str(n))
# final_result =[]
for item in range(len(n)):
if int(n[item])>0:
if n[item] != result[item]:
n[item] = str(result[item])
ans = "".join(n)
print(ans)
|
s680323602 | p04046 | u417309772 | 1599645428 | Python | Python (3.8.2) | py | Runtime Error | 28 | 9144 | 418 | P = 10**9+7
fac = [1]
ifac = [1]
ff = 1
for i in range(1,200001):
ff *= i
ff %= p
fac.append(ff)
ifac.append(pow(ff, p-2, p))
def ncr(n, r, p):
return (fac[n] * ifac[r] % p * ifac[n-r] % p);
h,w,a,b = map(int,input().split())
s = 0
nC = b-1
kC = 0
nD = w-b-1+h-1
kD = h-1
for i in range(h-a):
C = ncr(nC, kC, P)
D = ncr(nD, kD, P)
s = (s + C * D) % P
nC += 1
kC += 1
kD -= 1
nD -= 1
print(s)
|
s728668182 | p04046 | u107639613 | 1599448815 | Python | PyPy3 (7.3.0) | py | Runtime Error | 98 | 87292 | 1616 | import sys
def input(): return sys.stdin.readline().strip()
mod = 10**9+7
class Combination:
"""
O(n)の前計算を1回行うことで,O(1)でnCr mod mを求められる
n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
使用例:
comb = Combination(1000000)
print(comb(5, 3)) # 10
"""
def __init__(self, n_max, mod=10**9+7):
self.mod = mod
self.modinv = self.make_modinv_list(n_max)
self.fac, self.facinv = self.make_factorial_list(n_max)
def __call__(self, n, r):
return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod
def make_factorial_list(self, n):
# 階乗のリストと階乗のmod逆元のリストを返す O(n)
# self.make_modinv_list()が先に実行されている必要がある
fac = [1]
facinv = [1]
for i in range(1, n+1):
fac.append(fac[i-1] * i % self.mod)
facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
return fac, facinv
def make_modinv_list(self, n):
# 0からnまでのmod逆元のリストを返す O(n)
modinv = [0] * (n+1)
modinv[1] = 1
for i in range(2, n+1):
modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
return modinv
comb = Combination(10**5)
def main():
H, W, A, B = map(int, input().split())
ans = 0
for i in range(1, H - A + 1):
ans += comb(i + B - 2, i - 1) * comb(H - i + W - B - 1, H - i)
ans %= mod
print(ans)
if __name__ == "__main__":
main()
|
s448115246 | p04046 | u062691227 | 1598299857 | Python | PyPy3 (7.3.0) | py | Runtime Error | 96 | 74696 | 697 | H, W, A, B = map(int, open(0).read().split())
MOD = 10**9+7
def modperm(m, n, mod):
p = 1
for i in range(n):
p = p * (m - i) % mod
return p
def modcomb(m, n, mod):
if n > m - n:
n = m - n
p = modperm(m, n, mod)
q = pow(modperm(n, n, mod), -1, mod)
return p * q % mod
total = modcomb(H + W - 2, W - 1, MOD)
tmp = modcomb(A + W - 2, W - 1, MOD)
total -= tmp
for i in range(B - 1):
a = H - A + i
b = i + 1
c = W - i - 1
d = W + A - 2 - i
# print(a,b,c,d)
tmp = tmp * a * c % MOD
tmp = tmp * pow(b, MOD - 2, MOD) % MOD
tmp = tmp * pow(d, MOD - 2, MOD) % MOD
# print(tmp)
total = (total - tmp) % MOD
print(total) |
s641090957 | p04046 | u658181634 | 1598208277 | Python | Python (3.8.2) | py | Runtime Error | 1054 | 42560 | 637 | from operator import mul
from functools import reduce
from scipy.special import comb
# def cmb(n, r, mod):
# if ( r<0 or r>n ):
# return 0
# r = min(r, n-r)
# return g1[n] * g2[r] * g2[n-r] % mod
# def cmb(n, r):
# r = min(n-r, r)
# if r == 0:
# return 1
# over = reduce(mul, range(n, n - r, -1))
# under = reduce(mul, range(1, r + 1))
# return over // under
hwab = list(map(lambda x: int(x), input().split(" ")))
h = hwab[0]
w = hwab[1]
a = hwab[2]
b = hwab[3]
mod = 10**9 + 7
res = 0
for i in range(h-a):
res += comb(b+i-1, i) * comb(w-b+h-i-2, h-i-1)
print(int(res) % mod)
|
s755233800 | p04046 | u658181634 | 1598208087 | Python | Python (3.8.2) | py | Runtime Error | 26 | 9176 | 220 | hwab = list(map(lambda x: int(x), input().split(" ")))
h = hwab[0]
w = hwab[1]
a = hwab[2]
b = hwab[3]
mod = 10**9 + 7
res = 0
for i in range(h-a):
res += comb(b+i-1, i) * comb(w-b+h-i-2, h-i-1)
print(res % mod)
|
s429006145 | p04046 | u875113233 | 1595741287 | Python | Python (3.8.2) | py | Runtime Error | 550 | 11152 | 450 | def main():
import math
h,w,a,b=map(int,input().split())
h-=1
w-=1
a-=1
b-=1
N=math.factorial(w-b-1+h)/math.factorial(h)/math.factorial(w-b-1)
h1=h-1
while h1>a:
z=h-h1+b
z1=w-b-1+h1
N+=math.factorial(z)/math.factorial(h-h1)/math.factorial(b)*math.factorial(z1)/math.factorial(w-b-1)/math.factorial(h1)
h1-=1
print(int(N%(10**9+7)))
if __name__=="__main__":
main()
|
s847675542 | p04046 | u414920281 | 1595357867 | Python | Python (3.8.2) | py | Runtime Error | 26 | 9280 | 700 | a,b=map(int,input().split())
fac=[0]*200001#iの階乗mod(1000000007)
inv=[0]*200001#iの逆元mod(1000000007)
fac[0]=1
ans=0
for i in range(1,200001):
fac[i]=fac[i-1]*i%1000000007
inv[200000]=pow(fac[200000],1000000005,1000000007)
for i in range(199999,0,-1):
inv[i]=(inv[i+1]*(i+1))%1000000007
inv[0]=1
for i in range(h-a):
if i==0:
if h==1:
x=1
else:
x=(fac[w-b+h-2
-i]*inv[w-1-b]*inv[h-1-i])%1000000007
elif w==b+1:
x=(fac[b-1+i]*inv[b-1]*inv[i])%1000000007
else:
x=((fac[b-1+i]*inv[b-1]*inv[i])%1000000007)*((fac[w-b+h-2-i]*inv[w-b-1]*inv[h-1-i])%1000000007)
ans=(ans+x)%1000000007
print(ans) |
s447961783 | p04046 | u252160635 | 1594268449 | Python | Python (3.8.2) | py | Runtime Error | 2206 | 11640 | 294 | import math
def combinations_count(n, r):
return math.factorial(n+r) // (math.factorial(n) * math.factorial(r))
H, W, A, B = list(map(int, input().split()))
ans = 0
for i in range(H-A):
ans += combinations_count(B-1, i) * combinations_count(W-B-1, H-1-i)
print(int(ans%(1e+9 + 7))) |
s768002776 | p04046 | u896004073 | 1593313180 | Python | Python (3.8.2) | py | Runtime Error | 27 | 9592 | 444 | H, W, A, B = map(int, input().split())
N = 10**9 + 7
def factor(n,k):
assert n>=k
if n == k:
return 1
else:
return n*factor(n-1,k)
def comb(n,k):
if k < n/2:
return int(factor(n,n-k) / factor(k,0))
else:
return int(factor(n,k) / factor(n-k,0))
result = 0
for i in range(min(H-A, W-B)+1):
f1 = comb(B+H-A, B+i) % N
f2 = comb(W-B+A, A+i) % N
result += f1 * f2
print(result % N)
|
s933727690 | p04046 | u345710188 | 1592970075 | Python | Python (3.8.2) | py | Runtime Error | 2205 | 9664 | 485 | def irohamasu(i, j, H, W, A, B):
if (i >= H - A) and (j <= B - 1):
return 0
elif i == 0 & j == 0:
return 1
elif i == 0:
return irohamasu(i, j-1, H, W, A, B)
elif j == 0:
return irohamasu(i-1, j, H, W, A, B)
else:
return (irohamasu(i-1, j, H, W, A, B) + irohamasu(i, j-1, H, W, A, B))
H, W, A, B = map(int, input().split())
answer = irohamasu(H-1, W-1, H, W, A, B)
print(answer % (10**9 + 7)) |
s726350375 | p04046 | u552145906 | 1592292989 | Python | Python (3.4.3) | py | Runtime Error | 75 | 3968 | 973 |
import math
def re_factorial(n, r):
if n <= r:
return 1
return n * re_factorial(n-1,r)
H, W, A, B = map(int, input().split())
y = H - A - 1
ans = 0
for dx in range(B+1,W+1):
x = W - dx
if y >= dx-1:
xn = re_factorial(dx-1,1)
nn = re_factorial(dx-1+y, y)
Ansn = nn / xn
if x >= A-1:
ym = re_factorial(A-1,1)
mm = re_factorial(x+A-1,x)
Ansm = mm / ym
else:
xm = re_factorial(x,1)
mm = re_factorial(x+A-1,A-1)
Ansm = mm / xm
else:
yn = re_factorial(y,1)
nn = re_factorial(dx-1+y, dx-1)
Ansn = nn / yn
if x >= A-1:
ym = re_factorial(A-1,1)
mm = re_factorial(x+A-1,x)
Ansm = mm / ym
else:
xm = re_factorial(x,1)
mm = re_factorial(x+A-1,A-1)
Ansm = mm / xm
ans += Ansn * Ansm
ans = int(ans)%1000000007
print(int(ans)) |
s320744238 | p04046 | u552145906 | 1592290589 | Python | Python (3.4.3) | py | Runtime Error | 2026 | 5236 | 386 | import math
H, W, A, B = map(int, input().split())
y = H - A -1
ans = 0
for x in range(B,W):
yn = math.factorial(y)
xn = math.factorial(x)
nn = math.factorial(y+x)
Ansn = nn / (xn * yn)
xm = math.factorial(W-x-1)
ym = math.factorial(A-1)
mm = math.factorial(W-x-1+A-1)
Ansm = mm / (xm * ym)
ans += Ansn * Ansm
ans = ans%1000000007
print(int(ans)) |
s215993841 | p04046 | u189479417 | 1591892422 | Python | Python (3.4.3) | py | Runtime Error | 35 | 4340 | 530 | def cmb(n, r, mod):
if ( r<0 or r>n ):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7
size = 10**4
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range( 2, size + 1 ):
g1.append( ( g1[-1] * i ) % mod )
inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
g2.append( (g2[-1] * inverse[-1]) % mod )
H, W, A, B = map(int,input().split())
ans = 0
for i in range(W-B):
ans += cmb(H-A-1+(B+i), B+i, mod) * cmb(A-1+W-B-1-i, A-1, mod)
ans %= mod
print(ans) |
s291695475 | p04046 | u667472448 | 1591730889 | Python | Python (3.4.3) | py | Runtime Error | 147 | 13572 | 733 | mod = 1000000007
H, W, A, B = map(int, input().split())
factorial = [1]
for n in range(1, H+W):
factorial.append(factorial[n-1]*n%mod)
def power(x, y):
if y == 0:
return 1
elif y == 1:
return x % mod
elif y % 2 == 0:
return power(x, y/2)**2 % mod
else :
return power(x, y/2)**2 * x % mod
inverseFactorial = [0] * (H+W)
inverseFactorial[H+W-1] = power(factorial[H+W-1], mod-2)
for n in range(H+W-2, -1, -1):
inverseFactorial[n] = inverseFactorial[n+1] * (n+1) % mod
def combi(n, m):
return factorial[n] * inverseFactorial[m] * inverseFactorial[n-m] % mod
sum = 0
for i in range(B+1, W+1):
sum = (sum + combi(H-A-1+i-1, i-1) * combi(A-1+W-i, W-i)) % mod
print(sum) |
s599821710 | p04046 | u667472448 | 1591605218 | Python | Python (3.4.3) | py | Runtime Error | 2022 | 5136 | 300 | import math
h,w,a,b = map(int, input().split())
result = 0
for i in range(b,w):
result += ((math.factorial((i)+(h-a-1))) / (math.factorial(i) * math.factorial(h-a-1))) * ((math.factorial((w-i-1)+(a-1))) / (math.factorial(w-i-1)*math.factorial(a-1)))
result = int(result%(10**9 + 7))
print(result) |
s550946411 | p04046 | u139112865 | 1591203581 | Python | Python (3.4.3) | py | Runtime Error | 2286 | 319732 | 425 | h, w, a, b = map(int, input().split())
mod = 10 ** 9 + 7
n = h + w
f = [1 for _ in range(n)]
for i in range(1, n):
f[i] = f[i-1] * i
def f_inv(x):
return pow(f[x], mod-2, mod)
def comb(n, k):
return (f[n] * f_inv[k] % mod) * f_inv[n-k] % mod
ans = comb(h+w-2, h-1)
for i in range(b):
print(h-a+i, i)
print(a+w-i-2, a-1)
ans -= comb(h-a+i-1, i) * comb(a+w-i-2, a-1) % mod
ans %= mod
print(ans) |
s843052367 | p04046 | u373858851 | 1590538737 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 3952 | 365 | #Iroha and a grid
#abc 042
h,w,a,b=map(int,input().split())
mod=10**9+7
def dp(x,y,h,w,a,b):
if x==-2:
c=1
else:
if x==w-1 and y==h-1:
return 1
if x>=w or y>=h or (x<b and y>=h-a):
return 0
ans=dp(x+1,y,h,w,a,b)+dp(x,y+1,h,w,a,b)
return ans
print(dp(0,0,h,w,a,b)%mod)
|
s076339125 | p04046 | u373858851 | 1590538645 | Python | Python (3.4.3) | py | Runtime Error | 18 | 2940 | 363 | #Iroha and a grid
#abc 042
h,w,a,b=map(int,input().split())
mod=10**9+7
def dp(x,y,h,w,a,b):
if x==-2:
c=1
else:
if x==w-1 and y==h-1:
return 1
if x>=w or y>=h or (x<b and y>=h-a):
return 0
ans=dp(x+1,y,h,w,a,b)+dp(x,y+1,h,w,a,b)
return ans
print(dp(0,0,h,w,a,b)%mod)
|
s278222990 | p04046 | u373858851 | 1590538496 | Python | Python (3.4.3) | py | Runtime Error | 78 | 4592 | 414 | #Iroha and a grid
#abc 042
h,w,a,b=map(int,input().split())
mod=10**9+7
memo={}
def dp(x,y,h,w,a,b):
if (x,y) in memo:
return memo[(x,y)]
else:
if x==w-1 and y==h-1:
return 1
if x>=w or y>=h or (x<b and y>=h-a):
return 0
ans=dp(x+1,y,h,w,a,b)+dp(x,y+1,h,w,a,b)
memo[(x,y)]=ans
return memo[(x,y)]
ans=dp(0,0,h,w,a,b)%mod
print(ans)
|
s553943529 | p04046 | u373858851 | 1590538176 | Python | Python (3.4.3) | py | Runtime Error | 75 | 4592 | 407 | #Iroha and a grid
#abc 042
h,w,a,b=map(int,input().split())
mod=10**9+7
memo={}
def dp(x,y,h,w,a,b):
if (x,y) in memo:
return memo[(x,y)]
else:
if x==w-1 and y==h-1:
return 1
if x>=w or y>=h or (x<b and y>=h-a):
return 0
ans=dp(x+1,y,h,w,a,b)+dp(x,y+1,h,w,a,b)
memo[(x,y)]=ans
return memo[(x,y)]
print(dp(0,0,h,w,a,b)%mod)
|
s033577118 | p04046 | u557659226 | 1590224199 | Python | Python (3.4.3) | py | Runtime Error | 18 | 3064 | 712 | n,k = map(int,input().rstrip().split())
dislikes = list(map(int,input().rstrip().split()))
n = str(n)
len_n = len(n)
separate_n = [int(s) for s in n]
pay = separate_n.copy()
up_nextlevel = False
for i in range(len(separate_n)-1,-1,-1):
up_nextlevel = False
if separate_n[i] in dislikes:
for j in range(10):
num = separate_n[i]+j
if num > 9:
num -= 10
up_nextlevel = True
if not(num in dislikes):
pay[i] = num
break
else:
continue
if up_nextlevel:
for i in range(1,10):
if not(i in dislikes):
print(i,end="")
break
for p in pay:
print(p,end="") |
s289382506 | p04046 | u822179469 | 1590031747 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 729 | mod = 1000000007
H, W, A, B = map(int, raw_input().split())
factorial = [1]
for n in xrange(1, H+W):
factorial.append(factorial[n-1]*n%mod)
def power(x, y):
if y == 0 : return 1
elif y == 1 : return x % mod
elif y % 2 == 0 : return power(x, y/2)**2 % mod
else : return power(x, y/2)**2 * x % mod
inverseFactorial = [0] * (H+W)
inverseFactorial[H+W-1] = power(factorial[H+W-1], mod-2)
for n in xrange(H+W-2, -1, -1):
inverseFactorial[n] = inverseFactorial[n+1] * (n+1) % mod
def combi(n, m):
return factorial[n] * inverseFactorial[m] * inverseFactorial[n-m] % mod
sum = 0
for i in xrange(B+1, W+1):
sum = (sum + combi(H-A-1+i-1, i-1) * combi(A-1+W-i, W-i)) % mod
print sum |
s469438602 | p04046 | u822179469 | 1590031205 | Python | Python (3.4.3) | py | Runtime Error | 230 | 4092 | 497 | from math import factorial
h,w,a,b = map(int,input().split())
sg = 0
i = 0 #場合分け
svi = factorial(i+b)/factorial(i)/factorial(b)
vig = factorial(h-i-1+w-b-1)/factorial(h-i-1)/factorial(w-b-1)
sg = sg + svi*vig
# 1<= i <= h-a の時
for i in range(1,h-a):
svj = svi = factorial(i-1+b)/factorial(i-1)/factorial(b)
svi = factorial(i+b)/factorial(i)/factorial(b)
vig = factorial(h-i-1+w-b-1)/factorial(h-i-1)/factorial(w-b-1)
sg = sg + (svi-svj)*vig
print(int(sg%(10**9+7))) |
s712199502 | p04046 | u285891772 | 1589496369 | Python | PyPy3 (2.4.0) | py | Runtime Error | 167 | 38384 | 1278 | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, radians, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
lim = 2*10**5 #必要そうな階乗の限界を入力
#階乗#
fact = [1] * (lim+1)
for n in range(1, lim+1):
fact[n] = n * fact[n-1] % mod
#階乗の逆元#
fact_inv = [1]*(lim+1)
fact_inv[lim] = pow(fact[lim], mod-2, mod)
for n in range(lim, 0, -1):
fact_inv[n-1] = n*fact_inv[n]%mod
def C(n, r):
return (fact[n]*fact_inv[r]%mod)*fact_inv[n-r]%mod
H, W, A, B = MAP()
ans = 0
for n in range(B, W):
way = C(H-A-1+n, n)*C(W-n-1+A-1, A-1)%mod
ans = (ans+way)%mod
print(ans)
|
s146624685 | p04046 | u285891772 | 1589496313 | Python | PyPy3 (2.4.0) | py | Runtime Error | 174 | 38384 | 1311 | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
lim = 2*10**5 #必要そうな階乗の限界を入力
#階乗#
fact = [1] * (lim+1)
for n in range(1, lim+1):
fact[n] = n * fact[n-1] % mod
#階乗の逆元#
fact_inv = [1]*(lim+1)
fact_inv[lim] = pow(fact[lim], mod-2, mod)
for n in range(lim, 0, -1):
fact_inv[n-1] = n*fact_inv[n]%mod
def C(n, r):
return (fact[n]*fact_inv[r]%mod)*fact_inv[n-r]%mod
H, W, A, B = MAP()
ans = 0
for n in range(B, W):
way = C(H-A-1+n, n)*C(W-n-1+A-1, A-1)%mod
ans = (ans+way)%mod
print(ans)
|
s993478612 | p04046 | u285891772 | 1589496287 | Python | PyPy3 (2.4.0) | py | Runtime Error | 187 | 38256 | 1310 | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
lim = 2*10**5 #必要そうな階乗の限界を入力
#階乗#
fact = [1] * (lim+1)
for n in range(1, lim+1):
fact[n] = n * fact[n-1] % mod
#階乗の逆元#
fact_inv = [1]*(lim+1)
fact_inv[lim] = pow(fact[lim], mod-2, mod)
for n in range(lim, 0, -1):
fact_inv[n-1] = n*fact_inv[n]%mod
def C(n, r):
return (fact[n]*fact_inv[r]%mod)*fact_inv[n-r]%mod
H, W, A, B = MAP()
ans = 0
for n in range(B, W):
way = C(H-A-1+n, n)*C(W-n-1+A-1, A-1)%mod
ans = (ans+way)%mod
print(ans) |
s020909568 | p04046 | u285891772 | 1589496228 | Python | PyPy3 (2.4.0) | py | Runtime Error | 187 | 38384 | 1301 | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
lim = 2*10**5 #必要そうな階乗の限界を入力
#階乗#
fact = [1] * (lim+1)
for n in range(1, lim+1):
fact[n] = n * fact[n-1] % mod
#階乗の逆元#
fact_inv = [1]*(lim+1)
fact_inv[lim] = pow(fact[lim], mod-2, mod)
for n in range(lim, 0, -1):
fact_inv[n-1] = n*fact_inv[n]%mod
def C(n, r):
return (fact[n]*fact_inv[r]%mod)*fact_inv[n-r]%mod
H, W, A, B = MAP()
ans = 0
for n in range(B, W):
way = C(H-A-1+n, n)*C(W-n-1+A-1, A-1)%mod
ans = (ans+way)%mod
print(ans) |
s583284856 | p04046 | u285891772 | 1589496179 | Python | PyPy3 (2.4.0) | py | Runtime Error | 183 | 39876 | 1319 | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
lim = 2*10**5 #必要そうな階乗の限界を入力
#階乗#
fact = [1] * (lim+1)
for n in range(1, lim+1):
fact[n] = n * fact[n-1] % mod
#階乗の逆元#
fact_inv = [1]*(lim+1)
fact_inv[lim] = pow(fact[lim], mod-2, mod)
for n in range(lim, 0, -1):
fact_inv[n-1] = n*fact_inv[n]%mod
def C(n, r):
return (fact[n]*fact_inv[r]%mod)*fact_inv[n-r]%mod
H, W, A, B = MAP()
ans = 0
for n in range(B, W):
way = C(H-A-1+n, n)*C(W-n-1+A-1, A-1)%mod
ans = (ans+way)%mod
print(ans) |
s563818377 | p04046 | u285891772 | 1589495872 | Python | PyPy3 (2.4.0) | py | Runtime Error | 171 | 38256 | 1456 | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
def pow(x, n, p):
tmp = 1
while n:
if n%2:
tmp = tmp*x%mod
x = x*x%mod
n >>= 1
return tmp%mod
print(pow(2, 10, mod))
lim = 2*10**5 #必要そうな階乗の限界を入力
#階乗#
fact = [1] * (lim+1)
for n in range(1, lim+1):
fact[n] = n * fact[n-1] % mod
#階乗の逆元#
fact_inv = [1]*(lim+1)
fact_inv[lim] = pow(fact[lim], mod-2, mod)
for n in range(lim, 0, -1):
fact_inv[n-1] = n*fact_inv[n]%mod
def C(n, r):
return (fact[n]*fact_inv[r]%mod)*fact_inv[n-r]%mod
H, W, A, B = MAP()
ans = 0
for n in range(B, W):
way = C(H-A-1+n, n)*C(W-n-1+A-1, A-1)%mod
ans = (ans+way)%mod
print(ans)
|
s541449056 | p04046 | u285891772 | 1589495368 | Python | PyPy3 (2.4.0) | py | Runtime Error | 185 | 38496 | 1293 | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
lim = 2*10**5 #必要そうな階乗の限界を入力
#階乗#
fact = [1] * (lim+1)
for n in range(1, lim+1):
fact[n] = n * fact[n-1] % mod
#階乗の逆元#
fact_inv = [1]*(lim+1)
fact_inv[lim] = pow(fact[lim], mod-2, mod)
for n in range(lim, 0, -1):
fact_inv[n-1] = n*fact_inv[n]%mod
def C(n, r):
return (fact[n]*fact_inv[r]%mod)*fact_inv[n-r]%mod
H, W, A, B = MAP()
ans = 0
for n in range(B, W):
way = C(H-A-1+n, n)*C(W-n-1+A-1, A-1)%mod
ans = (ans+way)%mod
print(ans) |
s290427555 | p04046 | u285891772 | 1589494992 | Python | Python (3.4.3) | py | Runtime Error | 24 | 3572 | 1220 | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
lim = 2*10**6
fact = [1]*(lim+1)
for n in range(1, lim+1):
fact[n] = n*fact[n-1]%mod
fact_inv = [1]*(lim+1)
fact_inv[lim] = pow(fact[lim], mod-2, mod)
for n in range(lim, 0, -1):
fact_inv[n-1] = n*fact_inv[n]%mod
def C(n, r):
return (fact[n]*fact_inv[r]%mod)*fact_inv[n-r]%mod
H, W, A, B = MAP()
ans = 0
for n in range(B, W):
way = C(H-A-1+n, n)*C(W-n-1+A-1, A-1)%mod
ans = (ans+way)%mod
print(ans)
|
s242144826 | p04046 | u835534360 | 1589319816 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 3940 | 422 | def func(i, j, h, w, a, b):
if j == 0:
return 1
elif i == 0:
if j < h - a:
return 1
else:
return 0
else:
if 0 < i < b and h - a <= j < h:
return 0
else:
return func(i-1, j, h, w, a, b) + func(i, j-1, h, w, a, b)
h, w, a, b = (int(x) for x in input().split())
y = func(w-1, h-1, h, w, a, b)
y = y % (1000000007)
print(y)
|
s620083079 | p04046 | u922851354 | 1588459671 | Python | Python (3.4.3) | py | Runtime Error | 1413 | 5840 | 467 | import math
h,w,a,b=map(int, input().split())
def comb(n,r):
c=math.factorial(n)/(math.factorial(n-r)*math.factorial(r))
return c
def way_num(x, y):
return comb(x+y-2, x-1)
all_num=way_num(h, w)
no_num=0
for i in range(b):
to_here=way_num(h-a+1, i+1)
from_here=way_num(a, w-i)
if i>0:
overlap=way_num(h-a+1, i)*from_here
else:
overlap=0
no_num+=to_here*from_here-overlap
num=all_num-no_num
res=num%(10**9+7)
print(res) |
s188214041 | p04046 | u831081653 | 1588384477 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 7324 | 535 | h,w,a,b = map(int,input().split())
xList = list(range(w-b))
Py = h-a-1
mod = 10**9+7
def combination(x, y):
c = factorial(x)/(factorial(y)*factorial(x-y))
return c
def factorial(x):
f = 1
for i in range(1,x+1):
f *= i
return f
ans = 0
for x in xList:
Px = b+x
Gx = a+w-1-b-x
if x == 0:
buf = combination(Px+Py,Px)*combination(Gx,a)%mod
else:
buf = (combination(Px+Py,Px)-combination(Px+Py-1, Px-1))*combination(Gx,a)%mod
# print(Px,Py,Gx,a)
ans += buf
print(ans) |
s434053541 | p04046 | u831081653 | 1588384169 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 7328 | 524 | h,w,a,b = map(int,input().split())
xList = list(range(w-b))
Py = h-a-1
def combination(x, y):
c = factorial(x)/(factorial(y)*factorial(x-y))
return c
def factorial(x):
f = 1
for i in range(1,x+1):
f *= i
return f
ans = 0
for x in xList:
Px = b+x
Gx = a+w-1-b-x
if x == 0:
buf = combination(Px+Py,Px)*combination(Gx,a)
else:
buf = (combination(Px+Py,Px)-combination(Px+Py-1, Px-1))*combination(Gx,a)
# print(Px,Py,Gx,a)
ans += buf
print(ans%1000000007) |
s330023849 | p04046 | u486814557 | 1588141816 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 247 | H,W,A,B=map(int,input().split())
M=H-A
N=W-B
import math
def comb(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
a=B-1
b=H+N-2
c=N-1
S=sum(comb(a+k,a)*(comb(b-i,c)%(10**+7) for k in range(M))
print(S%(10**9+7)) |
s921265113 | p04046 | u486814557 | 1588141728 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 238 | H,W,A,B=map(int,input().split())
M=H-A
N=W-B
import math
def comb(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
a=B-1
b=H+N-2
c=N-1
S=sum(comb(a+k,a)*(comb(b-i,c) for k in range(M))
print(S%(10**9+7)) |
s170327385 | p04046 | u486814557 | 1588141647 | Python | Python (3.4.3) | py | Runtime Error | 442 | 4368 | 226 | H,W,A,B=map(int,input().split())
M=H-A
N=W-B
import math
def comb(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
a=B-1
b=H+N-2
c=N-1
S=sum(comb(a+k,a)*comb(b-i,c) for k in range(M))
print(S) |
s169045602 | p04046 | u308918401 | 1587854654 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 3492 | 256 | def fac(x):
y=1
for i in range(x):
y*=(i+1)
return(y)
def combi(i,j):
x=fac(i+j)/(fac(i)*fac(j))
return(int(x))
h,w,a,b=map(int,input().split())
ans=0
for i in range(w-b):
ans+=combi(b+i,h-a-1)*combi(w-b-i-1,a-1)
print(int(ans%(10**9+7))) |
s663572790 | p04046 | u308918401 | 1587850330 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 3540 | 491 | def fac(x):
y=1
for i in range(x):
y*=(i+1)
return(y)
def combi(i,j):
x=fac(i+j)/(fac(i)*fac(j))
return(int(x))
h,w,a,b=map(int,input().split())
all=combi(h-1,w-1)
z=[[0 for i in range(a)] for j in range(b)]
exc=0
for i in range(b):
for j in range(a):
if i==0:
z[i][j]=1
elif j==0:
z[i][j]=combi(h-a+j-1,i)+z[i-1][j]
else:
z[i][j]=z[i][j-1]+z[i-1][j]
for i in range(a):
exc+=z[b-1][i]*combi(a-i-1,w-b-1)
ans=all-exc
print(int(ans%(10**9+7))) |
s863431271 | p04046 | u308918401 | 1587828533 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 3504 | 276 | def fac(x):
y=1
for i in range(x):
y*=(i+1)
return(y)
def combi(i,j):
x=fac(i+j)/(fac(i)*fac(j))
return(x)
h,w,a,b=map(int,input().split())
all=combi(h-1,w-1)
exc=0
for i in range(a):
exc+=combi(a-1-i,b-1)*combi(i,w-b-1)
ans=all-exc
print(int(ans%(10^9+7)))
|
s861402974 | p04046 | u519923151 | 1587499044 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 4412 | 627 | H,W,A,B = map(int, input().split())
judge = (A+B)/(H+W)
a = H-A
res = 0
import math
def comba(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
if judge < 0.5:
base = comba((H+W-2), W-1, exact=True)
for i in range(1,B+1):
ex1 = comba(a-1+i-1,i-1)
ex2 = comba(A-1+W-i,W-i)
exres = ex1 *ex2
res = res + exres
result = (base -res) %1000000007
else:
for i in range(1,H-A+1):
ex1 = comba(i-1+B-1,i-1)
ex2 = comba(W-B-1+H-i,H-i)
exres = ex1 *ex2
res = res + exres
result = res %1000000007
print(result) |
s375877240 | p04046 | u519923151 | 1587497997 | Python | Python (3.4.3) | py | Runtime Error | 17 | 3064 | 277 | H,W,A,B = map(int, input().split())
a = H-A
res = 0
for i in range(1,B+1):
ex1 = comba(a-1+i-1,i-1)
print("ex1="+str(ex1))
ex2 = comba(A-1+W-i,W-i)
print("ex2="+str(ex2))
exres = ex1 *ex2
res = res + exres
result = (base -res) %1000000007
print(result) |
s735200795 | p04046 | u835924161 | 1587084692 | Python | Python (3.4.3) | py | Runtime Error | 17 | 2940 | 3791 | #include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<tuple>
#include<vector>
#include<cstdlib>
#include<cstdint>
#include<stdio.h>
#include<cmath>
#include<limits>
#include<iomanip>
#include<ctime>
#include<climits>
#include<random>
#include<queue>
using namespace std;
template <class T> using V = vector<T>;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
const long long INF = 1LL << 60;
using ll = long long;
using db = long double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using graph = V<V<int>>;
using pq = priority_queue<ll>;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a);
#define ALL(a) (a).begin(),(a).end()
ll Sum(ll n) {
ll m=0;
while(n){
m+=n%10;
n/=10;
}
return m;
}
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void Comuse() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++){
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
#define comuse Comuse()
ll combi(int n, int k){
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll perm(int n,int k){
if(n < k) return 0;
if(n < 0 || k < 0) return 0;
return fac[n] * (finv[k] % MOD) % MOD;
}
ll modpow(ll a,ll n,ll mod){
ll ans=1;
while(n>0){
if(n&1){
ans=ans*a%mod;
}
a=a*a%mod;
n>>=1;
}
return ans;
}
ll modinv(ll a, ll mod) {
return modpow(a, mod - 2, mod);
}
ll modcombi(int n,int k,int mod){
ll ans=1;
for(ll i=n;i>n-k;i--){
ans*=i;
ans%=mod;
}
for(ll i=1;i<=k;i++){
ans*=modinv(i,mod);
ans%=mod;
}
return ans;
}
ll lcm(ll a,ll b){
ll n;
n=a/gcd(a,b)*b;
return n;
}
vll div(ll n){
vll ret;
for(ll i=1;i*i<=n;i++){
if(n%i==0){
ret.push_back(i);
if(i*i!=n){
ret.push_back(n/i);
}
}
}
SORT(ret);
return (ret);
}
vector<bool> isprime(MAX+100,true);
void primeuse(){
isprime[0]=false;
isprime[1]=false;
for(int i=2;i<MAX+50;i++){
int up=sqrt(i)+1;
for(int j=2;j<up;j++){
if(i%j==0){
isprime[i]=false;
}
}
}
}
void Solve();
const int MAX_N = 131072;
//segment tree
int NN;
int seg[MAX_N*2-1];
void seguse(){
for(int i=0;i<2*NN-1;i++){
seg[i]=INT_MAX;
}
}
signed main(){
cin.tie(0);
ios::sync_with_stdio(false);
cout<<setprecision(20)<<fixed;
Solve();
}
/****************************************\
| Thank you for viewing my code:) |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka |
\****************************************/
//segtreeの葉の先頭の添え字はN-1
void Solve(){
//ll N=262144;
//vll segtree(2*N-1);
ll n;
cin>>n;
vll A(n);
FOR(i,0,n){
cin>>A[i];
}
REV(A);
ll ans=0;
ll now=1;
FOR(i,0,n){
ans+=now*A[i];
if(A[i]<10){
now*=10;
}
else if(A[i]<100){
now*=100;
}
else if(A[i]<1000){
now*=1000;
}
else if(A[i]<10000){
now*=10000;
}
else{
now*=100000;
}
now%=MOD;
ans%=MOD;
}
cout<<ans<<"\n";
} |
s461626085 | p04046 | u234091409 | 1586754043 | Python | PyPy3 (2.4.0) | py | Runtime Error | 171 | 38384 | 741 | # 解説を見て解いた。解説PDFの「B≦i≦Wを満たす全てのiについて」のWはW-1の間違い。
def make_table(h, w):
for i in range(1, h + w - 1):
fac_table.append(fac_table[-1] * i % mod) # i! mod 10**9+7
inv_table.append(pow(fac_table[-1], mod - 2, mod)) # (i!)^(-1) mod 10**9+7.
def comb(n, r):
return fac_table[n] * inv_table[n - r] * inv_table[r] % mod
def resolve():
H, W, A, B = map(int, input().split())
make_table(H, W)
_sum = 0
print(
sum(
[
comb(H - A - 1 + i, i) * comb(A - 1 + W - i - 1, A - 1) % mod
for i in range(B, W)
]
)
% mod
)
if __name__ == "__main__":
resolve() |
s957350133 | p04046 | u788337030 | 1586549875 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 3576 | 414 | import math
h, w, a, b = map(int, input().split())
ans = 0
rp = [h-a-1, b]
def f(x):
if x == 0:
return 1
else:
a = 1
for i in range(1, x+1):
a *= i
return a
def c(x, y):
return f(x)/(f(y)*f(x-y))
sum = 0
while True:
x = c(rp[0]+rp[1], rp[0]) * c((h-rp[0]-1)+(w-rp[1]-1), h-rp[0]-1)
sum += x
if rp[0] <= 0 or rp[1] >= w-1:
break
rp[0] -= 1
rp[1] += 1
print(math.floor(sum)) |
s083831303 | p04046 | u788337030 | 1586549837 | Python | Python (3.4.3) | py | Runtime Error | 2104 | 3512 | 390 | h, w, a, b = map(int, input().split())
ans = 0
rp = [h-a-1, b]
def f(x):
if x == 0:
return 1
else:
a = 1
for i in range(1, x+1):
a *= i
return a
def c(x, y):
return f(x)/(f(y)*f(x-y))
sum = 0
while True:
x = c(rp[0]+rp[1], rp[0]) * c((h-rp[0]-1)+(w-rp[1]-1), h-rp[0]-1)
sum += x
if rp[0] <= 0 or rp[1] >= w-1:
break
rp[0] -= 1
rp[1] += 1
print(sum) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.