submission_id
string
problem_id
string
status
string
code
string
input
string
output
string
problem_description
string
s746656996
p04046
Accepted
from math import factorial mod = 10**9 + 7 H, W, A, B = map(int, input().split()) memo_fact = [1] * (H + W - 1) memo_denometer = {} for i in range(1, H + W - 1): memo_fact[i] = memo_fact[i - 1] * i % mod def nCr(n,r): numerator = memo_fact[n] if (n, r) in memo_denometer: denometer = memo_denomete...
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...
s679606905
p04046
Accepted
H, W, A, B = map(int,input().split()) P = 10**9+7 # H, W, A, B = map(int,"2 3 1 1".split()) M = H+W-1 factlist = [1] * (H+W) factinvlist = [1] * (H+W) t = 1 for i in range(M): t = (t * (i+1)) % P factlist[i+1] = t t = pow(factlist[M],P-2,P) factinvlist[M] = t for i in range(M): t = (t * (M-i)) % P factinvlist[M-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...
s128137736
p04046
Accepted
import math H, W, A, B = map(int, input().split()) p = 10 ** 9 + 7 F = [1 for i in range(H + W + 1)] for i in range(1, H + W + 1): F[i] = F[i - 1] * i % p def fac(a, b): a = F[a + b] * pow(F[a], p - 2, p) * pow(F[b], p - 2, p) return a % p ans = 0 for h in range(H - A): ans += fac(h, B - 1) * fac(H - h - 1, W -...
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...
s194883361
p04046
Accepted
import math H, W, A, B = map(int, input().split()) p = 10 ** 9 + 7 F = [1 for i in range(H + W + 1)] for i in range(1, H + W + 1): F[i] = F[i - 1] * i % p def fac(a, b): a = F[a + b] * pow(F[a], p - 2, p) * pow(F[b], p - 2, p) return a % p if H - A < B: ans = 0 for h in range(H - A): ans += fac(h, B - 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...
s635896283
p04046
Accepted
h, w, a, b = [int(i) for i in input().split()] p = 10 ** 9 + 7 ans = 0 c = h-a-1 def fact(n, p=10**9 + 7): f = [1] for i in range(1, n+1): f.append(f[-1]*i%p) return f def invfact(n, f, p=10**9 + 7): inv = [pow(f[n], p-2, p)] for i in range(n, 0, -1): inv.append(inv[-1]*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...
s544387429
p04046
Accepted
h,w,a,b=map(int,input().split()) mod=10**9+7 fuc=[1] for i in range(1,h+w): e=fuc[i-1]*i fuc.append(e%mod) def com(n,k): com=(fuc[n]%mod)*pow(fuc[k],mod-2,mod)*pow(fuc[n-k],mod-2,mod) return com s=0 for i in range(1,h-a+1): s+=com(i-2+b,i-1)*com(w-b-1+h-i,w-b-1) print(s%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...
s283802692
p04046
Accepted
MOD = 10**9+7 h, w, a, b = list(map(int, input().split())) ans = 0 facts = [1] for i in range(1, h+w-1): facts.append((i*facts[i-1])%MOD) # print(facts[:20]) def get_path(n, r): return (facts[n] * pow(facts[r], MOD-2, MOD)%MOD * pow(facts[n-r], MOD-2, MOD)%MOD) % MOD y, x = h-a, b+1 while(True): pat...
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...
s585290602
p04046
Accepted
h, w, a, b = map(int, raw_input().split()) mod = 1000000007 inv = [0] * (h+w) fact = [0] * (h+w) def ex(x, y): if y == 0: return 1 elif y == 1: return x % mod elif y % 2 == 0: return ex(x, y/2) ** 2 % mod else: return ex(x, y/2) ** 2 * x % mod # factorial fact[0]=1 for j in range(1, h+w): fact[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...
s847931817
p04046
Accepted
H, W, A, B = (int(i) for i in input().split()) #H, W, A, B = (10, 7, 3, 4) #H, W, A, B = (2, 3, 1, 1) def mycomb(n,r): return (factorials[n] * pow(factorials[r],MOD-2,MOD) % MOD) * pow(factorials[n-r],MOD-2,MOD) % MOD MOD = int(1e9 + 7) factorials = [] factorials.append(1) for i in range(1, W + H): factoria...
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...
s096040657
p04046
Accepted
# 拡張ユークリッド互除法 # ax + by = gcd(a,b)の最小整数解を返す def egcd(a, b): if a == 0: return b, 0, 1 else: g, y, x = egcd(b % a, a) return g, x - (b // a) * y, y # mを法とするaの乗法的逆元 def modinv(a, m): g, x, y = egcd(a, m) if g != 1: raise Exception('modular inverse does not exist') els...
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...
s309254301
p04046
Accepted
def ext_gcd(a,b): """returns tuple (gcd(a,b), x, y) s.t. ax+by=gcd(a,b)""" if b==0: return (a,1,0) g,x,y = ext_gcd(b,a%b) return (g,y,x-a//b*y) def invmod_by_gcd(a,P): _,x,y = ext_gcd(a,P) return (x+P) % P F = [] FInv = [] def init_factorials(L,P): """initialize F and FInv less th...
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...
s147965354
p04046
Accepted
import sys sys.setrecursionlimit(10000000) p = 10**9+7 def power(a,b): if b == 0: return 1 elif b%2 == 0: return (power(a,b//2)**2)%p else: return (a*power(a,b//2)**2)%p def fact(a): if a <= 0: return 1 else: return (a*fact(a-1))%p H,W,A,B = map(int,input().st...
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...
s165369339
p04046
Accepted
H,W,A,B = map(int,input().split()) MOD = 10**9+7 fact = [1]*200001 t = 1 for i in range(1,200001): t = (t*i)%MOD fact[i] = t def ncr(n,r): return (fact[n] * pow(fact[r],MOD-2,MOD) % MOD) * pow(fact[n-r],MOD-2,MOD) % MOD Ans = 0 for i in range(H-A): Ans += ncr(i+B-1,i)*ncr(W-B+H-i-2,W-B-1) 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...
s292088103
p04046
Accepted
MOD = 10**9+7 N = 200000 p = [1] * (N+1) q = [1] * (N+1) for i in range(1, N+1): p[i] = (p[i-1]*(i)%MOD) q[0] = pow(p[-1], MOD-2, MOD) for i in range(1, N+1): q[i] = (N-i+1)*q[i-1]%MOD q.reverse() def nCk(n,k): if k > n or (k != 0 and n == 0): return 0 elif k == 0: return 1 else: ...
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...
s064986065
p04046
Accepted
MOD = 10**9+7 N = 200000 p = [1] * (N+1) q = [1] * (N+1) for i in range(1, N+1): p[i] = (p[i-1]*(i)%MOD) q[0] = pow(p[-1], MOD-2, MOD) for i in range(1, N+1): q[i] = (N-i+1)*q[i-1]%MOD q.reverse() def nCk(n,k): if k > n or n == 0: return 0 elif k == 0: return 1 else: 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...
s769283594
p04046
Accepted
h,w,a,b = (int(i) for i in input().split()) mod,n,ans = 10**9+7,h+w-2,0 fn,fk = [1]*n,[1]*n for i in range(n-1): fn[i+1] = (fn[i]*(i+2))%mod def power(n,k): if k==1: return n elif k%2==0: return power((n**2)%mod,k//2) else: return (n*power(n,k-1))%mod def comb(n,k): if n==0 or k==0 or n==k: return 1 else: 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...
s464876866
p04046
Accepted
H, W, A, B = map(int, input().split()) mod = 10**9 + 7 # 階乗 & 逆元計算 factorial = [1] inverse = [1] for i in range(1, 2*10**5): factorial.append(factorial[-1] * i % mod) inverse.append(pow(factorial[-1], mod-2, mod)) # 組み合わせ計算 def nCr(n, r): if n < r or n == 0 or r == 0: return 1 return 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...
s327541177
p04046
Accepted
import scipy.misc as scm h, w, a, b = [int(i) for i in input().split()] p = 10**9 + 7 ans = 0 def fact(n, p=10**9 + 7): f = [1] for i in range(1, n+1): f.append(f[-1]*i%p) return f def invfact(n, f, p=10**9 + 7): inv = [pow(f[n], p-2, p)] for i in range(n, 0, -1): inv.append(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...
s109246826
p04046
Accepted
import scipy.misc as scm h, w, a, b = [int(i) for i in input().split()] p = 10**9 + 7 ans = 0 def fact(n, p=10**9 + 7): f = [1] for i in range(1, n+1): f.append(f[-1]*i%p) return f def invfact(n, f, p=10**9 + 7): inv = [pow(f[n], p-2, p)] for i in range(n, 0, -1): inv.append(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...
s502101438
p04046
Accepted
MOD = 10**9+7 l = list(map(int,input().split())) h,w,a,b = l[0],l[1],l[2],l[3] def pow(x,n): res = 1 while n > 0: if n % 2 == 1: res = res*x % MOD x = x*x % MOD n = n >> 1 return res def comb(n,k): return (fact[n]*inv[k] % MOD)*inv[n-k] % MOD fact = [1]*1000000 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...
s332148598
p04046
Accepted
import itertools import math H,W,A,B=map(int,raw_input().split()) mod=10**9+7 FACT={} n=1 for i in range(H+W-1): if i==0: n=1 else: n=(n*i)%mod FACT[i]=n #print FACT def C(n,r): return (FACT[n]*pow(FACT[r],10**9+5 ,mod)*pow(FACT[n-r],10**9+5 ,mod)) %mod p=0 for i in range(B,W): p+=C(H-A-1+i,i)*C(A-1+W-i-1,W...
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...
s989775515
p04046
Accepted
import itertools import math H,W,A,B=map(int,raw_input().split()) mod=10**9+7 FACT={} FACT_INVERSE={} n=1 for i in range(H+W-1): if i==0: n=1 else: n=(n*i)%mod FACT[i]=n #print FACT def C(n,r): return (FACT[n]*pow(FACT[r],10**9+5 ,mod)*pow(FACT[n-r],10**9+5 ,mod)) %mod p=0 for i in range(B,W): p+=C(H-A-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...
s257644569
p04046
Accepted
M = 10**9 + 7 L = 200000 Fm = {} inverseFm = {} x = 1 for i in range(L): Fm[i] = x x = x * (i + 1) % M def inverseFm(x): result = pow(Fm[x], M - 2, M) return result def C(n, r): result = Fm[n] * inverseFm(r) * inverseFm(n - r) % M return result def solve(H, W, A, B): result = 0 f...
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...
s788806022
p04046
Accepted
M = 10**9 + 7 L = 200000 Fm = {} inverseFm = {} x = 1 for i in range(L): Fm[i] = x x = x * (i + 1) % M def inverseFm(x, cache={}): if x in cache: return cache[x] result = pow(Fm[x], M - 2, M) cache[x] = result return result def C(n, r): result = Fm[n] * inverseFm(r) * inverseFm(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...
s743298272
p04046
Accepted
H,W,A,B=map(int,input().split()) mod=10**9+7 #繰り返し二乗法 def great_power(x, y): if y == 0: return 1 elif y == 1: return x % mod elif y % 2 == 0: return great_power(x, y//2)**2 % mod else: return great_power(x, y//2)**2 * x % mod #階乗計算 factorial=[1] for i in range(1,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...
s905446670
p04046
Accepted
def d_Iroha_and_a_Grid(H, W, A, B): # フェルマーの小定理でnCrを定義 n = H + W - 2 M = 10**9 + 7 factrial = [1] * (n + 2) for k in range(1, n + 2): factrial[k] = (factrial[k - 1] * k) % M fact_inv = [1] * (n + 2) fact_inv[n + 1] = pow(factrial[n + 1], M - 2, M) for k in range(n, -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...
s869168366
p04046
Accepted
mod = 1000000007 facto = [1]*200001 tmp = 1 for i in range(1,200001): tmp = (tmp*i)%mod facto[i] = tmp def ncr(n,r): return (facto[n] * pow(facto[r],mod-2,mod) % mod) * pow(facto[n-r],mod-2,mod) % mod h,w,a,b = map(int,input().split()) ret = 0 for i in range(h-a): ret += ncr(b-1+i,i)*ncr(h-i-1+w-b-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...
s292690386
p04046
Accepted
def power_func(a,b,p): """a^b mod p を求める""" if b==0: return 1 if b%2==0: d=power_func(a,b//2,p) return d*d %p if b%2==1: return (a*power_func(a,b-1,p ))%p H,W,A,B=map(int, input().split()) p=10**9+7 X=[1] #階乗テーブル for i in range(1,H+W-1): X+=[ (X[-1]*i) %p ] Y=[1]*(H+W-1) #階乗の逆元テーブル Y[H+W-2]=po...
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...
s468564545
p04046
Accepted
def power_func(a,b,p): """a^b mod p を求める""" if b==0: return 1 if b%2==0: d=power_func(a,b//2,p) return d*d %p if b%2==1: return (a*power_func(a,b-1,p ))%p H,W,A,B=map(int, input().split()) p=10**9+7 ans=0 X=[1] #階乗テーブル for i in range(1,H+W-1): X+=[ (X[-1]*i) %p ] Y=[1]*(H+W-1) #階乗の逆元テーブル Y[H+W-...
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...
s370159088
p04046
Accepted
from math import factorial H,W,A,B=map(int, input().split()) p=10**9+7 ans=0 X=[1,1] #階乗テーブル Y=[1,1] #階乗の逆元テーブル calc=[0,1] #逆元計算用テーブル for i in range( 2, H+W-2 ): X.append( ( X[-1] * i ) % p ) calc.append( ( -calc[p % i] * (p//i) ) % p ) Y.append( (Y[-1] * calc[-1]) % p ) for i in range(B,W): ans+=(X[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...
s536736075
p04046
Accepted
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """042-d""" import sys def factorialMod(x, mod): """Calculate modulo of funcotial 'x'.""" assert isinstance(x, int) assert x >= 0 assert isinstance(mod, int) assert mod >= 0 if x == 0: return 1 return (x % mod) * factorialMod(x - 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...
s042843726
p04046
Accepted
H,W,A,B= map(int, input().split()) mod = 10**9+7 N=W-B g1 = [1, 1] # 元テーブル g2 = [1, 1] #逆元テーブル inverse = [0, 1] #逆元テーブル計算用テーブル for i in range( 2, H+W-2 ): g1.append( ( g1[-1] * i ) % mod ) inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod ) g2.append( (g2[-1] * inverse[-1]) % mod ) #以下の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...
s009479592
p04046
Accepted
class Combination: def __init__(self, mod): self.mod = mod self.fact = [1] * (2 * 10 ** 5 + 1) for i in range(1, 2 * 10 ** 5 + 1): self.fact[i] = i * self.fact[i - 1] % self.mod def nCr(self, n, k): a = self.fact[n] % self.mod b = (self.fact[k] * self.fact...
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...
s040692862
p04046
Accepted
mod = 10**9+7 H, W, A, B = list(map(int, input().split(" "))) fact = [1] * (2 * 10**5+1) for i in range(1, 2*10**5+1): fact[i] = i * fact[i-1] % mod def comb(n, k): a = fact[n] % mod b = (fact[k] * fact[n-k]) % mod b_ = pow(b, mod-2, mod) return (a * b_) % mod ans = 0 for i in range(B, W): ...
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...
s787049394
p04046
Accepted
import operator as op from functools import reduce from math import factorial import sys modulus = 1000000007 factorial = [1, 1] for i in range(2, 2000001): factorial.append(factorial[-1] * i % modulus) factorial_inv_rev = [pow(factorial[-1], 1000000005, modulus)] for i in range(len(factorial)-1, 1, -1): 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...
s320667884
p04046
Accepted
MOD = 10**9+7 def add(a,b): return (a+b) % MOD def mul(a,b): return (a*b) % MOD def pow(a,n): ans = 1 mag = a for b in reversed(str(bin(n))): if b == 'b': break if b == '1': ans = mul(ans, mag) mag = mul(mag, mag) return ans def inv(a): return pow(a, MOD-2) H,W,A,B = map(int,raw_inp...
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...
s609950436
p04046
Accepted
from sys import stdin, stdout, stderr mod = 10**9 + 7 def solve(): def binom(n, k): res = (modfact[n] * factinv[k]) % mod res = (res * factinv[n - k]) % mod return res h, w, a, b = map(int, input().split()) ans = 0 modfact = [1] * (h + w) factinv = [1] * (h + w) for 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...
s297984459
p04046
Accepted
mod = 10**9+7 H, W, A, B = [int(_) for _ in input().split()] fact = [1] * (2 * 10**5+1) for i in range(1, 2*10**5+1): fact[i] = i * fact[i-1] % mod def comb(n, k): a = fact[n] % mod b = (fact[k] * fact[n-k]) % mod b_ = pow(b, mod-2, mod) return (a * b_) % mod ans = 0 for w in range(B, W): 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...
s695750896
p04046
Accepted
C = int(1e9) + 7 H, W, A, B = map(int, input().split()) fact = [1] for x in range(1, H + W - 2): fact.append( (x * fact[x-1]) % C ) factinv = [1] * (H + W -2) factinv[H + W - 3] = pow(fact[H + W -3], C-2, C) for x in reversed(range(2, H + W -3)): factinv[x] = ( factinv[x+1] * (x+1) ) % C def nCr(n,r): return ( f...
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...
s098204449
p04046
Accepted
h,w,a,b=map(int,raw_input().split(' ')) mod=1000000007 inv=[0]*(h+w) fact=[0]*(h+w) def ex(x,y): if y==0: return 1 elif y==1: return x%mod elif y%2==0: return ex(x,y/2)**2%mod else: return ex(x,y/2)**2*x%mod #factorial fact[0]=1 for j in range(1,h+w): fact[j]=fact[j-1]*j%mod inv[h+w-1]=ex(fact[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...
s365983865
p04046
Accepted
H, W, A, B = map(int, input().split()) class Combin(object): def __init__(self, max_n, mod = 10**9 + 7): self.max_n = max_n self.mod = mod self.fac = self._init_factorials() self.inv = self._init_inv() def _init_factorials(self): N = self.max_n 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...
s008256714
p04046
Accepted
C = int(1e9) + 7 h, w, a, b = [int(x) for x in input().split()] fact = [1] for x in range(1, h + w - 2): fact.append((x * fact[x - 1]) % C) factinv = [1] * (h + w - 2) factinv[h + w - 3] = pow(fact[h + w - 3], C - 2, C) for x in reversed(range(2, h + w - 3)): factinv[x] = (factinv[x + 1] * (x + 1)) % C def 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...
s429379172
p04046
Accepted
M=10**9+7;H,W,A,B=map(int,input().split());Z=C=1 for I in range(H-1):Z=C=C*(W+H-B-2-I)*pow(I+1,M-2,M)%M for I in range(1,H-A):C=C*(B-1+I)*(H-I)*pow(I*(W+H-B-1-I),M-2,M)%M;Z+=C print(Z%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...
s690909960
p04046
Accepted
M=10**9+7;F=lambda X:pow(X,M-2,M);H,W,A,B=map(int,input().split());Z=C=1 for I in range(H-1):Z=C=C*(W+H-B-2-I)*F(I+1)%M for I in range(1,H-A):C=C*(B-1+I)*(H-I)*F(I*(W+H-B-1-I))%M;Z+=C print(Z%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...
s838503748
p04046
Accepted
M=10**9+7;F=lambda X:pow(X,M-2,M);H,W,A,B=map(int,input().split());Z=C=1 for I in range(H-1):Z=C=C*(W+H-B-2-I)*F(I+1)%M for I in range(1,H-A):C=C*(B-1+I)*(H-I)%M*F(I*(W+H-B-1-I))%M;Z=(Z+C)%M print(Z)
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...
s208681054
p04046
Accepted
M=10**9+7;F=lambda X:pow(X,M-2,M);H,W,A,B=map(int,input().split());Z=C=1 for I in range(H-1):Z=C=C*(W+H-B-2-I)*F(I+1)%M for I in range(1,H-A):C=C*(B-1+I)*(H-I)*F(I*(W+H-B-1-I))%M;Z=(Z+C)%M print(Z)
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...
s837370264
p04046
Accepted
M=10**9+7;F=[pow(X,M-2,M)for X in range(2*10**5)];H,W,A,B=map(int,input().split());Z=C=1 for I in range(H-1):Z=C=C*(W+H-B-2-I)*F[I+1]%M for I in range(1,H-A):C=C*(B-1+I)*F[I]*(H-I)*F[W+H-B-1-I]%M;Z=(Z+C)%M print(Z)
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...
s017148839
p04046
Accepted
M=10**9+7;F=lambda X:pow(X,M-2,M);H,W,A,B=map(int,input().split());Z=C=1 for I in range(H-1):Z=C=C*(W+H-B-2-I)*F(I+1)%M for I in range(1,H-A):C=C*(B-1+I)*F(I)*(H-I)*F(W+H-B-1-I)%M;Z=(Z+C)%M print(Z)
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...
s279500873
p04046
Accepted
F=lambda X:pow(X,M-2,M);M=10**9+7;H,W,A,B=map(int,input().split());Z=C=1 for I in range(min(W-1-B,H-1)):Z=C=C*(W+H-B-2-I)*F(I+1)%M for I in range(1,H-A):C=C*(B-1+I)*F(I)*(H-I)*F(W+H-B-1-I)%M;Z=(Z+C)%M print(Z)
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...
s582303315
p04046
Accepted
def Combination_mod(n, k): ret = f[n] ret = (ret * finv[k]) % mod ret = (ret * finv[n - k]) % mod return ret mod = 1000000007 h, w, a, b = map(int,input().split()) x = [] xi = b xj = h - a - 1 while xi < w and xj >= 0: x.append([xi, xj]) xi += 1 xj -= 1 n = w + h f = [0] * n finv = [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...
s316420238
p04046
Runtime Error
# 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, 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...
s670718509
p04046
Runtime Error
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 ...
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...
s282585295
p04046
Runtime Error
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: ...
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...
s680323602
p04046
Runtime Error
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, 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...
s728668182
p04046
Runtime Error
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**...
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...
s448115246
p04046
Runtime Error
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 ...
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...
s641090957
p04046
Runtime Error
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, 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...
s755233800
p04046
Runtime Error
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)
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...
s429006145
p04046
Runtime Error
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...
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...
s847675542
p04046
Runtime Error
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(...
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...
s447961783
p04046
Runtime Error
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)))
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...
s768002776
p04046
Runtime Error
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 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...
s933727690
p04046
Runtime Error
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) + irohama...
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...
s726350375
p04046
Runtime Error
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 / 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...
s320744238
p04046
Runtime Error
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 ...
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...
s215993841
p04046
Runtime Error
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 )...
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...
s291695475
p04046
Runtime Error
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 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...
s599821710
p04046
Runtime Error
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)
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...
s550946411
p04046
Runtime Error
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) ...
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...
s843052367
p04046
Runtime Error
#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) ...
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...
s076339125
p04046
Runtime Error
#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) 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...
s278222990
p04046
Runtime Error
#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,...
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...
s553943529
p04046
Runtime Error
#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,...
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...
s033577118
p04046
Runtime Error
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(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...
s469438602
p04046
Runtime Error
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) sv...
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...
s712199502
p04046
Runtime Error
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 imp...
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...
s146624685
p04046
Runtime Error
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 cop...
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...
s993478612
p04046
Runtime Error
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 cop...
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...
s020909568
p04046
Runtime Error
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 ...
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...
s563818377
p04046
Runtime Error
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...
s541449056
p04046
Runtime Error
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...
s290427555
p04046
Runtime Error
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...
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...
s242144826
p04046
Runtime Error
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, ...
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...
s620083079
p04046
Runtime Error
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: over...
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...
s188214041
p04046
Runtime Error
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 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...
s434053541
p04046
Runtime Error
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: ...
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...
s330023849
p04046
Runtime Error
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))
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...
s921265113
p04046
Runtime Error
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))
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...
s170327385
p04046
Runtime Error
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)
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...
s169045602
p04046
Runtime Error
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)))
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...
s663572790
p04046
Runtime Error
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: ...
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...
s863431271
p04046
Runtime Error
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)))
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...
s861402974
p04046
Runtime Error
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(...
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...
s375877240
p04046
Runtime Error
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)
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...
s735200795
p04046
Runtime Error
#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...
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...
s461626085
p04046
Runtime Error
# 解説を見て解いた。解説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] *...
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...
s957350133
p04046
Runtime Error
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 +=...
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...
s083831303
p04046
Runtime Error
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...
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...
s987187315
p04046
Runtime Error
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...
s399167431
p04046
Runtime Error
import math # Function to find modulo inverse of b. It returns # -1 when inverse doesn't # modInverse works for prime m def modInverse(b,m): g = math.gcd(b, m) if (g != 1): # print("Inverse doesn't exist") return -1 else: # If b and m are relatively prime, ...
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...