submission_id string | problem_id string | status string | code string | input string | output string | problem_description string |
|---|---|---|---|---|---|---|
s639233427 | p04046 | Accepted | h,w,a,b=map(int,input().split())
factorials=[]
inverses=[]
MOD=10**9+7
factorials.append(1)
curr=1
for i in range(1,h+w+1):
curr=(curr*i)%MOD
factorials.append(curr)
for i in range(h+w+1):
inverses.append(pow(factorials[i],MOD-2,MOD))
ans=0
for i in range(h-a):
ans=(ans+factorials[b-1+i]*factorials[h-2-i+w-b]*i... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s316045630 | p04046 | Accepted | mod = 10 ** 9 + 7
fact = [1]
inv = [1]
for i in range(200000):
fact.append(fact[i] * (i + 1) % mod)
inv.append(pow(fact[i + 1], mod - 2, mod))
def ncr(n, r):
if n < 0 or r < 0 or n - r < 0:
return 0
return fact[n] * inv[r] * inv[n - r] % mod
h, w, a, b = map(int, input().split())
ans = ncr(h + w - 2, h - 1)... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s979367224 | p04046 | Accepted | h,w,a,b=map(int,input().split())
mod=pow(10,9)+7
# コンビネーション、さらに高速。あらかじめO(N)の計算をすることでのちの計算が早くなる
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
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range( 2, 200000 + 1 ):
g1.append( ( g1[-1] * i... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s958216650 | p04046 | Accepted | 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 = 2*10**5
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... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s183501806 | p04046 | Accepted | def ext_euclid(a, b):
# return (x, y, gcd(a, b)) such that a * x + b * y = gcd(a, b)
if b == 0:
return 1, 0, a
y, x, v = ext_euclid(b, a % b)
y -= (a // b) * x
return x, y, v
def mod_inv(a, mod):
x, _, _ = ext_euclid(a, mod)
return x % mod
def comb_list_1(H, W, A, B, mod, modinv_... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s759041184 | p04046 | Accepted | h, w, a, b = map(int, input().split())
mod = 10 ** 9 + 7
n = h + w
f = [1 for _ in range(n)]
f_inv = [1 for _ in range(n)]
for i in range(1, n):
f[i] = f[i-1] * i % mod
f_inv[i] = pow(f[i], 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 rang... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s160315145 | p04046 | Accepted | import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
def main():
h,w,a,b = map(int,ipt().split())
... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s660671319 | p04046 | Accepted | g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
MOD = 10**9+7
for i in range(2, 2*10**5+1):
g1.append((g1[-1] * i) % MOD)
inverse.append((-inverse[MOD % i] * (MOD // i)) % MOD)
g2.append((g2[-1] * inverse[-1]) % MOD)
def comb(n, r, mod=MOD):
if r < 0 or r > n:
return 0
r = min(r, n - r)
return... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s113472321 | p04046 | Accepted | # 練習
import math
h,w,a,b = list(map(int, input().split()))
p = 10**9+7
# 方針
# (0,0) ~ (0,w-1)
# (h-1,0 )~ (h-1,w-1)で考える
# 通れないのは(h-a) ~ (h-1)行かつ(0) ~ (b-1) 列のところ
# b <= i <= w-1 のiについて1,2,3の組み合わせはそれぞれ以下の通り
# 1, (0,0) ~ (h-a-1,i) (h-a-1+i)! /(h-a-1)! * i!
# 2, (h-a-1,i )~(h-a,i) 1
# 3, (h-a,i) ~ (h-1,w-1) (... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s616725498 | p04046 | Accepted | MOD=10**9+7
H,W,A,B=map(int,input().split())
def invmod(a):
return pow(a,MOD-2,MOD)
def comb_mod(n,r):
if 0<=r<=n:
return fact_dic[n]*fact_inv_dic[r]*fact_inv_dic[n-r]
else:
return 0
fact_dic={0:1}
fact_inv_dic={0:1}
fact_mod=1
for i in range(1,H+W-1):
fact_mod=(fact_mod*i)%MOD
fact_dic[i]=fact_mod
... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s302106136 | p04046 | Accepted | MOD=10**9+7
H,W,A,B=map(int,input().split())
def invmod(a):
return pow(a,MOD-2,MOD)
def comb_mod(n,r):
if 0<=r<=n:
return fact_dic[n]*fact_inv_dic[r]*fact_inv_dic[n-r]
else:
return 0
fact_dic={0:1}
fact_inv_dic={0:1}
fact_mod=1
for i in range(1,H+W-1):
fact_mod=(fact_mod*i)%MOD
fact_dic[i]=fact_mod
... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s189114842 | p04046 | Accepted | MOD=10**9+7
H,W,A,B=map(int,input().split())
def invmod(a):
return pow(a,MOD-2,MOD)
def comb_mod(n,r):
return fact_dic[n]*fact_inv_dic[r]*fact_inv_dic[n-r]
fact_dic={0:1}
fact_inv_dic={0:1}
fact_mod=1
for i in range(1,H+W-1):
fact_mod=(fact_mod*i)%MOD
fact_dic[i]=fact_mod
fact_inv_dic[i]=invmod(fact_mod)
... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s351728424 | p04046 | Accepted | import math
p=1000000007
g1=[1,1]
g2=[1,1]
inverse=[0,1]
for i in range(2,2*(10**5)+1):
g1.append((g1[-1]*i)%p)
inverse.append((-inverse[p%i]*(p//i))%p)
g2.append((g2[-1]*inverse[-1])%p)
def cmb2(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 chwp(h,w,p):
... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s629168942 | p04046 | Accepted | h,w,a,b = map(int,input().split())
mod = 10**9+7
fact = [1,1]
finv = [1,1]
inv = [0,1]
for i in range(2,h+w+5):
fact.append((fact[-1]*i)%mod)
inv.append((inv[mod%i]*(mod-mod//i))%mod)
finv.append((finv[-1]*inv[-1])%mod)
def nCr(n,r,mod):
if r > n:
return 0
else:
return fact[n]... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s016401409 | p04046 | Accepted | import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15
def main():
H,W,A,B = map(int,input().split())
MAXN = H + W + 3
factorial = [1]
for i in range(1,MAXN + 1):
factorial.append(factorial[-1]*i%MOD)
inv_factorial = [-1] * (MAXN + 1)
inv_factorial[-1] = pow(factori... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s380416209 | p04046 | Accepted | mod = 10 ** 9 + 7
N = 10 ** 6
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
for i in range(2, N + 1):
fact.append(fact[-1] * i % mod)
inv.append((-inv[mod % i] * (mod // i)) % mod)
factinv.append((factinv[-1] * inv[-1]) % mod)
def combi_mod(n, r, p):
if (r < 0) or (n < r):
return 0
r = min(r... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s716750790 | p04046 | Accepted | # -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1
def main():
H,W,A,B=map(int,input().split()... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s483029157 | p04046 | Accepted | H,W,A,B = map(int,input().split())
N=H+W
fact = [0]*(N+1)
ifact = [0]*(N+1)
inv = [0]*(N+1)
p=10**9+7
def combination(n):
fact[0] = 1
fact[1] = 1
ifact[0] = 1
ifact[1] = 1
inv[1] = 1
for i in range(2,n+1):
fact[i] = (fact[i-1]*i)%p
inv[i] = p - inv[p%i]*(p//i)%p
ifact[i]... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s820510133 | p04046 | Accepted | h,w,a,b = map(int, input().split())
import math
ans = 0
mod = 10**9+7
l =[i for i in range(1,h+w+2)]
for i in range(1,len(l)-1):
l[i+1] = l[i+1]*l[i]%mod
l = [1]+ l
gyakugen = [pow(l[i], mod-2, mod) for i in range(1, len(l))]
gyakugen = [1] + gyakugen
for p in range(1, w-b+1):
ans += l[(h-a-1+b+p-1)]*l[w-(b+p)+... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s773831563 | p04046 | Accepted | H, W, A, B = map(int, input().split())
mod = int(1e9) + 7
def inved(a):
x, y, u, v, k, l = 1, 0, 0, 1, a, mod
while l != 0:
x, y, u, v = u, v, x - u * (k // l), y - v * (k // l)
k, l = l, k % l
return x % mod
fact = [1 for _ in range(H+W+A+B+1)]
invf = [1 for _ in range(H+W+A+B+1)]
for i in range(H+W+A+B)... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s196254093 | p04046 | Accepted | # Combination
MOD = 10**9+7
MAX = 2*10**5
fac = [1,1] + [0]*MAX
finv = [1,1] + [0]*MAX
inv = [0,1] + [0]*MAX
for i in range(2,MAX+2):
fac[i] = fac[i-1] * i % MOD
inv[i] = -inv[MOD%i] * (MOD // i) % MOD
finv[i] = finv[i-1] * inv[i] % MOD
def comb(n,r):
if n < r: return 0
if n < 0 or r < 0: return 0
... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s047331751 | p04046 | Accepted | #ライブラリの点検
class Data():
def __init__(self):
self.power=1
self.rev=1
class Combi():
def __init__(self,N,mod):
self.lists=[Data() for _ in range(N+1)]
self.mod=mod
for i in range(2,N+1):
self.lists[i].power=((self.lists[i-1].power)*i)%self.mod
sel... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s375158317 | p04046 | Accepted | #!/usr/bin/env python3
import sys
# import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgette... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s317456342 | p04046 | Accepted | 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
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from ... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s080701961 | p04046 | Accepted | 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... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s973821399 | p04046 | Accepted | 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... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s239755774 | p04046 | Accepted | 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... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s529214189 | p04046 | Accepted | def combmod_pre(N, p):
'''
sample usage:
p = 10**9+7
N = 10**6
fact, finv = combmod_pre(N, p)
combmod(n, r, p)
'''
fact = [1, 1]
finv = [1, 1]
inv = [0, 1]
for i in range(2, N+1):
fact.append((fact[-1] * i) % p)
inv.append((-inv[p % i] * (p // ... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s194170678 | p04046 | Accepted | def combmod(n, r, p):
if r < 0 or n < r:
return 0
return fact[n] * finv[r] * finv[n-r] % p
p = 10**9+7
N = 10**6
fact = [1, 1]
finv = [1, 1]
inv = [0, 1]
for i in range(2, N+1):
fact.append((fact[-1] * i) % p)
inv.append((-inv[p % i] * (p // i)) % p)
finv.append((finv[-1] * inv[-1]) % p)
... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s067452857 | p04046 | Accepted | MOD = 10**9+7
h,w,a,b = map(int,input().split())
n = h+w
fac = [1]*(n+1)
fac_inv = [0]*(n+1)
for i in range(n):
fac[i+1] = (fac[i] * (i+1)) %MOD
fac_inv[-1] = pow(fac[-1],MOD-2,MOD)
for i in range(n,0,-1):
fac_inv[i-1] = (fac_inv[i] * i) % MOD
def comb(n,k):
if k<0 or k>n:
return 0
x = ... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s292934544 | p04046 | Accepted | 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 #出力の制限
N = 2*10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
g1.append( ( g1[-1] * i ) % mod )
inverse... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s633679559 | p04046 | Accepted | import sys
def comb(n, r, mod=None):
if r == 0 or r == n:
return 1
r = min([r, n-r])
x, y = 1, 1
ans = 1
for i in range(1, r+1):
if mod:
x *= n+1-i
y *= i
x %= mod
y %= mod
else:
ans *= n+1-i
ans //= i
... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s586146267 | p04046 | Accepted | MOD=10**9+7
UPPERLIMIT=2*(10**5)+1
MODMUL=[1, 1]+[0]*(UPPERLIMIT-1)
for i in range(2, UPPERLIMIT+1):
MODMUL[i]=MODMUL[i-1]*i%MOD
MODDIV=[1]*UPPERLIMIT+[pow(MODMUL[-1], MOD-2, MOD)]
for i in range(UPPERLIMIT, 0, -1):
MODDIV[i-1]=MODDIV[i]*i%MOD
H, W, A, B=map(int, input().split())
ans=(((MODMUL[H+W-2]*MODDIV[H-1])... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s236037854 | p04046 | Accepted | H, W, A, B = map(int, input().split())
MAX = 2 * 10 ** 5 + 1
MOD = 10 ** 9 + 7
# Factorial
fac = [0] * (MAX + 1)
fac[0] = 1
fac[1] = 1
for i in range(2, MAX + 1):
fac[i] = fac[i - 1] * i % MOD
# Inverse factorial
finv = [0] * (MAX + 1)
finv[MAX] = pow(fac[MAX], MOD - 2, MOD)
for i in reversed(range(1, MAX + ... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s469473134 | p04046 | Accepted |
a,b,c,d = list(map(int, input().split()))
def cmb(n, r, p):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n-r] % p
p = 10**9+7
N = 10 ** 6 + 2
fact = [1, 1] # fact[n] = (n! mod p)
factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1] # factinv... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s840046869 | p04046 | Accepted | MOD = 10 ** 9 + 7
def prepare(n):
global MOD
modFacts = [0] * (n + 1)
modFacts[0] = 1
for i in range(n):
modFacts[i + 1] = (modFacts[i] * (i + 1)) % MOD
invs = [1] * (n + 1)
invs[n] = pow(modFacts[n], MOD - 2, MOD)
for i in range(n, 1, -1):
invs[i - 1] = (invs[i] * i) % MO... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s925317109 | p04046 | Accepted | #coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter, deque
import itertools
#from scipy.misc import comb
MOD = 10**9+7
H,W,A,B = map(int,input().split())
def comb(a,b):
p = fac[a-b]*fac[b]%MOD
return fac[a]*pow(p,MOD-2,MOD)%MOD
fac=[1]
for i in range(H+W):
fac.... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s791598446 | p04046 | Accepted | h,w,a,b=map(int,input().split())
inv=[0]*(2*max(h,w)+1)
fact=[0]*(2*max(h,w)+1)
inv[0]=1;fact[0]=1
mod=10**9+7
for i in range(1,2*max(h,w)+1):
fact[i]=fact[i-1]*i%mod
inv[-1]=pow(fact[-1],mod-2,mod)
for i in range(2*max(h,w),0,-1):
inv[i-1]=inv[i]*i%mod
ans=0
for yoko in range(b+1,w+1):
re=fact[yoko-1+h-1-a... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s810498265 | p04046 | Accepted | H, W, A, B = [int(_) for _ in input().split()]
mod = 10**9 + 7
X = [i for i in range(H + W + 1)]
X[0] = 1
for i in range(2, H + W + 1):
X[i] = X[i - 1] * i % mod
Y = X.copy()
Y[-1] = pow(Y[-1], mod - 2, mod)
for i in range(H + W, 1, -1):
Y[i - 1] = i * Y[i] % mod
def comb(x, y):
return X[x] * Y[y] *... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s693966858 | p04046 | Accepted | U = 2*10**5
MOD = 10**9+7
fact = [1] * (U+1)
fact_inv = [1] * (U+1)
# 階乗のテーブル作成
for i in range(1, U+1):
fact[i] = (fact[i-1] * i) % MOD
# 階乗の逆元のテーブル作成
fact_inv[U] = pow(fact[U], MOD-2, MOD)
for i in range(U, 0, -1):
fact_inv[i-1] = (fact_inv[i] * i) % MOD
def comb(n, k):
if k < 0 or k > n:
retu... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s033787017 | p04046 | Accepted | def prepare(n, MOD):
f = 1
factorials = [1]
for m in range(1, n + 1):
f *= m
f %= MOD
factorials.append(f)
inv = pow(f, MOD - 2, MOD)
invs = [1] * (n + 1)
invs[n] = inv
for m in range(n, 1, -1):
inv *= m
inv %= MOD
invs[m - 1] = inv
return ... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s932614654 | p04046 | Accepted | H, W, A, B = map(int, input().split())
mod = 10**9 + 7
fact = [1] * (H+W+1)
fact_inv = [1] * (H+W+1)
for i in range(1, H+W+1):
fact[i] = i * fact[i-1] % mod
fact_inv[H+W] = pow(fact[H+W], mod-2, mod)
for i in range(1, H+W+1)[::-1]:
fact_inv[i-1] = i * fact_inv[i] % mod
comb = lambda n, k: fact[n] * fact_inv[k]... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s418523274 | p04046 | Accepted | mod = 10 ** 9 + 7
fac_table = [1 for i in range(200001)]
inv_table = [1 for i in range(200001)]
def make_table(h, w):
for i in range(1, h + w - 1):
fac_table[i] = fac_table[i - 1] * i % mod
inv_table[i] = pow(fac_table[i], mod - 2, mod)
def comb(n, r):
return fac_table[n] * inv_table[n - r]... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s257839064 | p04046 | Accepted | H, W, A, B = map(int, input().split())
mod = 10**9 + 7
U = 2 * 10**5
factorial = [1 for _ in range(U + 1)]
for i in range(1, U + 1):
factorial[i] = (factorial[i - 1] * i) % mod
inverse = [1 for _ in range(U + 1)]
inverse[U] = pow(factorial[U], mod - 2, mod)
for i in range(U, 0, -1):
inverse[i - 1] = (inverse[... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s456454409 | p04046 | Accepted | import math
import time
DIV_VALUE = 10**9 + 7
def calcModOfPow(a, n, p):
btm = a
ans = 1
while n != 0:
# print('btm: {}'.format(btm))
if n & 1:
ans = (ans * btm) % p
# print('ans: {}'.format(ans))
n = n>>1
btm = (btm**2) % p
# print(n)
r... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s475829799 | p04046 | Accepted | class cmbs(object):
def __init__(self, mod):
self.mod = mod
self.g1 = [1, 1]
self.g2 = [1, 1]
inverse = [0, 1]
for i in range(2, 10 ** 6 + 1):
self.g1.append((self.g1[-1] * i) % mod)
inverse.append((-inverse[mod % i] * (mod // i)) % mod)
se... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s805821572 | p04046 | Accepted | class nCrMod():
def __init__(self, mod):
self.mod = mod
self.fac = [1, 1]
self.finv = [1, 1]
self.inv = [0, 1]
def prep(self, n):
mod = self.mod
f, fi = self.fac[-1], self.finv[-1]
for i in range(len(self.fac), n + 1):
fn = f * i % mod
... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s298845173 | p04046 | Accepted | class CombinationFermat:
def __init__(self):
"""O(MAX)で前計算しておく→以降comb(a,b)はO(1)で取得可能
"""
MOD = 10**9 + 7
MAX = 2*10**5
self.fac = [0]*MAX # self.fac[n]: (n!) mod p
self.finv = [0]*MAX # self.finv[n]: (n!)^-1 mod p
self.inv = [0]*MAX # inv[n]: (n)^-1 m... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s876810494 | p04046 | Accepted | MOD = 10**9 + 7
MAX = 2*10**5
fac = [0]*MAX # fac[n]: (n!) mod p
finv = [0]*MAX # finv[n]: (n!)^-1 mod p
inv = [0]*MAX # inv[n]: (n)^-1 mod -p
def comb_init():
global fac, finv, inv
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
fac[i] = fac[i-1] * i % MO... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s587846681 | p04046 | Accepted | class Calc:
def __init__(self, max_value, mod):
"""combination(max_value, all)"""
fact = [-1] * (max_value + 1)
fact[0] = 1
fact[1] = 1
for x in range(2, max_value + 1):
fact[x] = x * fact[x - 1] % mod
invs = [1] * (max_value + 1)
invs[max_value] ... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s810428530 | p04046 | Accepted | # -*- coding: utf-8 -*-
#コンビネーション
def cmb(n, r):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n-r] % mod
N = 2 * 10 ** 5 + 1000 # N は必要分だけ用意する
mod = pow(10, 9) + 7
fact = [1, 1] # fact[n] = (n! mod p)
factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p)
in... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s475392102 | p04046 | Accepted | def main():
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 # 出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] # 逆元テーブル
inverse = [0, 1] # 逆元テーブル計算用テーブル
for i in range(2, N + 1):
... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s206436338 | p04046 | Accepted | from itertools import permutations
import sys
sys.setrecursionlimit(10 ** 6)
from bisect import *
from collections import *
from heapq import *
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def SI(): ret... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s691061124 | p04046 | Accepted | def cmb1(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
h,w,a,b=map(int,input().split())
# 前処理
mod=10**9+7 #出力の制限
n=10**6
g1=[1,1] # 元テーブル
g2=[1,1] # 逆元テーブル
inverse=[0,1] #逆元テーブル計算用テーブル
for i in range(2,n+1):
g1.append((g1[-1]*i)%mod)
inverse.append((... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s004713854 | p04046 | Accepted | class Combination:
def __init__(self, size, mod=10**9 + 7):
self.size = size + 2
self.mod = mod
self.fact = [1, 1] + [0] * size
self.factInv = [1, 1] + [0] * size
self.inv = [0, 1] + [0] * size
for i in range(2, self.size):
self.fact[i] = self.fact[i - 1]... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s336401635 | p04046 | Accepted | import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string impor... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s194116611 | p04046 | Accepted | #!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s824602153 | p04046 | Accepted | memo=[0]*(10**6+1)
memo[0]=memo[1]=1
mod=10**9+7
for i in range(2,10**6+1):
memo[i]=(memo[i-1]*i)%mod
def comb(n,k,p):
return (memo[n]*pow(memo[k],p-2,p)*pow(memo[n-k],p-2,p))%mod
h,w,a,b=map(int,input().split())
ans=0
for i in range(h-a):
ans+=(comb(b+i-1,i,mod)*comb(h-i-1+w-b-1,w-b-1,mod))%mod
ans%=mod
print(... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s941355053 | p04046 | Accepted | H, W, A, B = [int(_) for _ in input().split()]
mod = 10**9 + 7
X = [i for i in range(H + W + 1)]
X[0] = 1
for i in range(2, H + W + 1):
X[i] = X[i - 1] * i % mod
Y = X.copy()
Y[-1] = pow(Y[-1], mod - 2, mod)
for i in range(H + W, 1, -1):
Y[i - 1] = i * Y[i] % mod
def comb(x, y):
return X[x] * Y[y] *... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s800338032 | p04046 | Accepted |
# Function to find modulo inverse of b. It returns
# -1 when inverse doesn't
# modInverse works for prime m
def gcd(b, m):
if b == 0:
return m
return gcd(m%b, b)
def modInverse(b,m):
g = gcd(b, m)
if (g != 1):
# print("Inverse doesn't exist")
return -1
else:
# I... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s902230742 | p04046 | Accepted | MOD = 10**9+7
def modpow(base, pow, mod):
res = 1
while pow > 0:
if pow & 1:
res = res * base % mod
base = base**2 % mod
pow >>= 1
return res
def modmul(a, b, mod):
return a*b % mod
def solve(h,w,a,b):
fact = [0]*(h+w+1)
fact[0] = 1
fact_inv = [0]*(h+w+1)
fact_inv[0] = 1
for i in ... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s718583588 | p04046 | Accepted | h, w, a, b = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
kkai = [1]
for i in range(1, 210000):
kkai.append(kkai[-1] * i % mod)
def kai(x, p=mod):
return kkai[x]
def comb(a, b, p=mod):
if a < 0 or b < 0:
return 0
elif a < b:
return 0
c = 1
c *= kai(a, p)
c *= pow(... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s952392467 | p04046 | Accepted | H,W,A,B = map(int,input().split())
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.mod... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s711753237 | p04046 | Accepted | #!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")
MOD = 1000000007 # type: int
class Combination(object):
def __init__(self, N, mod=MOD):
fac, finv, inv = [0]*(N+1), [0]*(N+1), [0]*(N+1)
fac[:2] = 1, 1
finv[:2] = 1, 1
inv[1] = 1
for i in r... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s937115372 | p04046 | Accepted | H, W, A, B = map(int, input().split())
MOD = 1000000007
fac = [1, 1]
inverse = [0, 1]
ifac = [1, 1]
for i in range(2, H+W):
fac.append((fac[-1] * i) % MOD)
inverse.append((-inverse[MOD % i] * (MOD // i)) % MOD)
ifac.append((ifac[-1] * inverse[i]) % MOD)
def f(n):
return fac[B+n+H-A-1] * fac[W-B-1-n+A-1] ... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s669159115 | p04046 | Accepted | H,W,A,B=map(int,input().split())
MAX_NUM = 2*10**5 + 1
pr = 10**9+7
fac = [0 for _ in range(MAX_NUM)]
finv = [0 for _ in range(MAX_NUM)]
inv = [0 for _ in range(MAX_NUM)]
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2,MAX_NUM):
fac[i] = fac[i-1] * i % pr
inv[i] = pr - inv[pr%i] * (pr /... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s380631765 | p04046 | Accepted | from operator import mul
from functools import reduce
def cmb(n, r, p):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n-r] % p
p = 10 ** 9 + 7
N = 10 ** 6
fact = [1, 1] # fact[n] = (n! mod p)
factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p)
inv ... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s651322526 | p04046 | Accepted | mod = 10 ** 9 + 7
def extGCD(a, b):
if b == 0:
return a, 1, 0
g, y, x = extGCD(b, a%b)
y -= a//b * x
return g, x, y
def moddiv(a, b):
_, inv, _ = extGCD(b, mod)
return (a * inv) % mod
N = 2 * 10 ** 5 + 10
fact = [0] * (N)
fact[0] = 1
for i in range(1, N):
fact[i] = (fact[i-1] * i) ... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s866868141 | p04046 | Accepted | h, w, a, b = map(int, input().split())
MOD = 1000000007
def modPow(a, x, p):
res = 1
while (x > 0):
if (x % 2 != 0):
res = (res * a) % p
a = (a * a) % p
x /= 2
return res
fact = [None] * 220000
for i in range(1, 220000):
fact[0] = 1
fact[i] = i * fact[i - 1]... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s075777515 | p04046 | Accepted | h,w,a,b = map(int, input().split())
def find_power(n,mod=10**9+7):
powlist=[0]*(n+1)
powlist[0]=1
powlist[1]=1
for i in range(2,n+1):
powlist[i]=powlist[i-1]*i%(mod)
return powlist
def find_inv_power(n):
powlist=find_power(n)
check=powlist[-1]
first=1
uselist=[0]*(n+1)
se... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s907387093 | p04046 | Accepted | import sys
input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def main():
mod=10**9+7
H,W,A,B=MI()
N=H+W
def cmb(n, r, mod):
if (r < 0) or (n < r):
return 0
r = min(r... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s337405092 | p04046 | Accepted | N=2*10**5+3
mod=10**9+7
fac=[1]*(N+1)
for i in range(1,N+1):
fac[i]=fac[i-1]*i%mod
inv_fac=[1]*(N+1)
inv_fac[N]=pow(fac[N],mod-2,mod)
for i in range(N-1,0,-1):
inv_fac[i]=inv_fac[i+1]*(i+1)%mod
def nCr(n,r):
if n<0 or r<0 or r>n:
return 0
return fac[n]*inv_fac[r]%mod*inv_fac[n-r]%mod
h,w,a,b=map... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s715567132 | p04046 | Accepted |
class Cmber:
def __init__(self,gensize,mod=10**9+7):
self.mod = mod
self.g1=[1,1]
self.g2 = [1, 1] #逆元テーブル
self.inverse = [0, 1] #逆元テーブル計算用テーブル
self.getgen(gensize)
def getgen(self,N):
for i in range( 2, N + 1 ):
self.g1.append( ( self.g1[-1] * i ) %... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s989067102 | p04046 | Accepted | h,w,a,b=map(int,input().split())
N=h+w
mod=10**9+7
fac=[1]*(N+2)
inv=[1]*(N+2)
t=1
for i in range(1,N+2):
t*=i
t%=mod
fac[i]=t
t=pow(fac[N+1],mod-2,mod)
for i in range(N+1,0,-1):
inv[i]=t
t*=i
t%=mod
def comb(n,r):
return fac[n]*inv[n-r]*inv[r]%mod
c=[0]
for i in range(h-a):
c.append(com... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s985696220 | p04046 | Accepted | h,w,a,b=map(int,input().split())
mod=10**9+7
ans=0
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 #出力の制限
N = h+w+1
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
g1.append( ... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s435632479 | p04046 | Accepted | import math
h, w, a, b = map(int, input().split())
#divmod
mod = pow(10,9)+7
def divmod(num, mod=10**9+7):
return pow(num, mod-2, mod)
#combination
def comb(a,b):
p=fact[a-b]*fact[b]%mod
return fact[a]*divmod(p)%mod
fact = [1]
for i in range(1,h+w):
fact.append(i*fact[i-1]%mod)
#print(fact)
ans = 0
for j... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s530108711 | p04046 | Accepted | class ModInt:
def __init__(self, num, mod):
self.num = num
self.mod = mod
def __str__(self):
return str(self.num)
def __repr__(self):
return "ModInt(num: {}, mod: {}".format(self.num, self.mod)
def __add__(self, other):
ret = self.num + other.num
ret %=... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s500868525 | p04046 | Accepted | mod=10**9+7
h,w,a,b=map(int,input().split())
def comb(a,b):
p=fac[a-b]*fac[b]%mod
return fac[a]*pow(p,mod-2,mod)%mod
fac=[1]
for i in range(h+w):
fac.append(fac[-1]*(i+1)%mod)
ans=0
for i in range(w-b):
p=comb(h-a-1+b+i,b+i)*comb(w-b-i-2+a,a-1)
ans+=p%mod
ans%=mod
print(ans) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s091927857 | p04046 | Accepted | import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)
# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
return [ int(s) for s in input().split(" ")]
# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
return [ int(input()) for _ in range(n)]
# 改行またはスペース... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s743875436 | p04046 | Accepted | # D - いろはちゃんとマス目
def cmb1(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
h,w,a,b=map(int,input().split())
# 前処理
mod=10**9+7 #出力の制限
n=10**6
g1=[1,1] # 元テーブル
g2=[1,1] # 逆元テーブル
inverse=[0,1] #逆元テーブル計算用テーブル
for i in range(2,n+1):
g1.append((g1[-1]*i)%mod)
in... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s038983669 | p04046 | Accepted | h, w, a, b = map(int, input().split())
def cmb1(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 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
g1.append( ( g1[-1] *... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s816650220 | p04046 | Accepted | def main():
H, W, A, B = (int(i) for i in input().split())
m = H + W + 3
MOD = 10**9 + 7
fac = [0] * m
finv = [0] * m
inv = [0] * m
def COMBinitialize(m):
fac[0] = 1
finv[0] = 1
if m > 1:
fac[1] = 1
finv[1] = 1
inv[1] = 1
... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s313640545 | p04046 | Accepted | MOD = 10**9+7
fac = [1 for k in range(200010)]
inv = [1 for k in range(200010)]
finv = [1 for k in range(200010)]
for k in range(2,200010):
fac[k] = (fac[k-1]*k)%MOD
inv[k] = (MOD - inv[MOD%k] * (MOD // k))%MOD
finv[k] = (finv[k - 1] * inv[k]) % MOD;
def nCr(n,r):
return (fac[n]*finv[r]*finv[n-r])%MOD
... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s348368747 | p04046 | Accepted | class Combination():
# コンストラクタ
def __init__(self, N:int, P:int):
self.N = N
self.P = P
# fact[i] = (i! mod P)
self.fact = [1, 1]
# factinv[i] = ((i!)^(-1) mod P)
self.factinv = [1, 1]
# factinv 計算用
self.inv = [0, 1]
for i in range(... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s669878261 | p04046 | Accepted | H,W,A,B = map(int, input().split())
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 #出力の制限
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, H+W + 1 ):
g1.append( ( g1[-1] * i ) % mod )... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s077226498 | p04046 | Accepted | import sys
def comb(n, r, fact, revfact, mod):
return (fact[n] * revfact[n-r] * revfact[r]) % mod
def solve():
H, W, A, B = map(int, input().split())
mod = 7 + 10 ** 9
fact = [1] * (H + W + 4)
revfact = [1] * (H + W + 4)
for i in range(1, H + W + 4): fact[i] = (i * fact[i-1]) % mod
revfact... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s161678019 | p04046 | Accepted | import sys
mod = pow(10, 9) + 7
sys.setrecursionlimit(pow(10, 8))
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-1)//2)**2 * x % mod
def mul(a, b):
return ((a % mod) * (b % mod)) % mod
def div(a... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s058736282 | p04046 | Accepted | class Combination:
"""
SIZEが10^6程度以下の二項係数を何回も呼び出したいときに使う
使い方:
comb = Combination(SIZE, MOD)
comb(10, 3) => 120
"""
def __init__(self, N, MOD=10 ** 9 + 7):
self.MOD = MOD
self.fact, self.inv = self._make_factorial_list(N)
def __call__(self, n, k):
if k < 0 or k >... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s638339919 | p04046 | Accepted | MAX = 2*10**5+100
fact = [0]*MAX
inv = [0]*MAX
finv = [0]*MAX
def C_init():
fact[0] = 1
fact[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
fact[i] = fact[i-1]*i%MOD
inv[i] = MOD-inv[MOD%i]*(MOD//i)%MOD
finv[i] = finv[i-1]*inv[i]%MOD
def C(n, r... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s740150393 | p04046 | Accepted | h, w, a, b = map(int, input().split())
mod = 10**9 + 7
fac = [1, 1]
inv = [1, 1]
finv = [1, 1]
for i in range(2, h+w+5):
fac.append(fac[i-1] * i % mod)
inv.append(mod - inv[mod%i] * (mod//i) % mod)
finv.append(finv[i-1] * inv[i] % mod)
def nck(n, k):
if n < k:
return 0
if n < 0 or k < 0:
... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s887423083 | p04046 | Accepted | class Combination:
"""
SIZEが10^6程度以下の二項係数を何回も呼び出したいときに使う
使い方:
comb = Combination(SIZE, MOD)
comb(10, 3) => 120
"""
def __init__(self, N, MOD=10 ** 9 + 7):
self.MOD = MOD
self.fact, self.inv = self._make_factorial_list(N)
def __call__(self, n, k):
if k < 0 or k >... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s778888518 | p04046 | Accepted | h,w,a,b = map(int, input().split())
mx = max(h,w)
mod = 10**9+7
fac = [1]*(h+w+1)
for i in range(1,h+w+1):
fac[i]=fac[i-1]*i%mod
rev = [1]*(mx+1)
rev[-1] = pow(fac[mx], mod-2, mod)
for i in range(mx-1, -1, -1):
rev[i] = rev[i+1]*(i+1)%mod
const = rev[h-a-1]*rev[a-1]%mod
ans = 0
for i in range(b,w):
ans += fac[h-a+i-... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s479470866 | p04046 | Accepted | h, w, a, b = map(int, input().split())
m = 10**9 + 7
fac = [1, 1]
inv = [1, 1]
finv = [1, 1]
for i in range(2, w+h+5):
fac.append(fac[i-1] * i % m)
inv.append(m - inv[m%i] * (m//i) % m)
finv.append(finv[i-1] * inv[i] % m)
def nck(n, k):
if n < k:
return 0
if n < 0 or k < 0:
return ... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s147744319 | p04046 | Accepted | class Factorial:
def __init__(self, n, mod=10**9+7):
self.fac = [0] * (n+1)
self.ifac = [0] * (n+1)
self.fac[0] = 1
self.ifac[0] = 1
self.mod = mod
modmod = self.mod - 2
for i in range(n):
self.fac[i+1] = self.fac[i] * (i+1) % self.mod
... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s633470199 | p04046 | Accepted | H,W,A,B = map(int,input().split())
mod = 10**9+7
x1 = [1 for i in range(H+W)]
xi = [1 for i in range(H+W)]
num = 1
def power2(a,b,p):
if b == 0:
return 1
if b%2 == 0:
d = power2(a,b//2,p)
return (d*d)%p
return (a*power2(a,b-1,p))%p
for i in range(1,H+W):
num = (num*i)%mod
x1[... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s585366330 | p04046 | Accepted | import sys
input = sys.stdin.buffer.readline
import copy
def main():
H,W,A,B = map(int,input().split())
MOD = 10**9+7
fac = [0 for _ in range(H+W+1)]
fac[0],fac[1] = 1,1
inv = copy.deepcopy(fac)
invfac = copy.deepcopy(fac)
for i in range(2,H+W+1):
fac[i] = (fac[i-1]*i)%MOD
... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s431447671 | p04046 | Accepted | H, W, A, B = map(int, input().split())
mod = 10**9+7
F = [1]*200010
p = 1
for i in range(1, len(F)):
F[i] = p = p*i%mod
def comb(n, k):
return F[n]*pow(F[n-k], mod-2, mod)*pow(F[k], mod-2, mod)%mod
ans = 0
for h in range(H-A):
x = comb(B-1+h, h) # 右にB-1回、下にh回移動する方法の数
y = comb(W+H-B-h-2, H-h-1) # 右にW-B-1回、下にH... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s531459836 | p04046 | Accepted | mod = 10**9 + 7
h, w, a, b = map(int, input().split())
fact = [1] * (h + w + 1)
invf = [1] * (h + w + 1)
invn = [1] * (h + w + 1)
for i in range(2, h + w + 1):
fact[i] = fact[i-1] * i % mod
invn[i] = (-invn[mod % i]) * (mod // i) % mod
invf[i] = invf[i-1] * invn[i] % mod
count = 0
for i in range(min(h-a, w-b)):... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s697581947 | p04046 | Accepted | H,W,A,B = map(int,input().split())
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
N = 10**6 #出力の制限
mod = 10**9+7
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
g1.append( ( g1[-1] * i... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
s849254979 | p04046 | Accepted | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
MOD = 10**9+7
fac = [1, 1]
f_inv = [1, 1]
inv = [0, 1]
def modcmb(n, r, mod):
if n < 0 or r < 0 or r > n:
return 0
return fac[n] * f_inv[r] * f_inv[n-r] % mod
def main():
H,W,A,B = map(int, readline()... | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the b... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.