submission_id
string
problem_id
string
status
string
code
string
input
string
output
string
problem_description
string
s026120904
p04046
Accepted
H,W,A,B = map(int,input().split()) MOD = (10**9)+7 D = [0,2, 9, 11, 14, 15, 17, 19, 20, 23, 24, 25, 27, 28, 29] def inv(a): ans = 1 hoge = a for count in range(31): if (count) in D: ans *= hoge ans %= MOD hoge *= hoge hoge %= MOD return ans g = [1]*(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...
s342324390
p04046
Accepted
mod=10**9+7 g1=[1,1] g2=[1,1] inverse=[0,1] h,w,a,b=map(int,input().split()) n=h+w for i in range(2,n+1): g1.append((g1[-1]*i)%mod) inverse.append((-inverse[mod % i]*(mod//i))%mod) g2.append((g2[-1]*inverse[-1])%mod) def cmb(n,r): return g1[n]*g2[r]*g2[n-r]%mod ans=0 while a<h and b<w: ans=(ans+cm...
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...
s432972669
p04046
Accepted
class Combination: def __init__(self, size=100, 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, size + 2): self.fact[i] = self.fact[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...
s901634067
p04046
Accepted
H, W, A, B = map(int, input().split()) MAX = 200000 MOD = 1000000007 fac = [0]*MAX finv = [0]*MAX inv = [0]*MAX fac[0] = 1 fac[1] = 1 finv[0] = 1 finv[1] = 1 inv[1] = 1 for i in range(2, MAX): fac[i] = fac[i-1]*i%MOD inv[i] = MOD - inv[MOD%i]*(MOD//i)%MOD finv[i] = finv[i-1]*inv[i]%MOD # sum_{i=B}^{W-1} C_{H-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...
s004650250
p04046
Accepted
h,w,a,b=map(int,input().split());m=10**9+7;f=[1] for i in range(h+w):f+=[f[-1]*(i+1)%m] def comb(a,b,m):return f[a]*pow(f[b],m-2,m)*pow(f[a-b],m-2,m)%m x=0 for i in range(b,w):x+=comb(h-a+i-1,i,m)*comb(a+w-i-2,a-1,m)%m print(x%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...
s015769866
p04046
Accepted
high, width, y, x = map(int, input().split()) def nCr(n, r): return ((((fact[n]*finv[n-r])%mod)*finv[r])%mod) mod = 10**9 + 7 inv = mod - 2 maxn = high + width - 2 fact = [0] * (maxn+1) finv = [0] * (maxn+1) fact[0] = fact[1] = 1 finv[0] = finv[1] = 1 # 階乗を求める for i in range(2, maxn+1): fact[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...
s568419484
p04046
Accepted
h, w, a, b = map( int, input().split() ) SIZE = h+w+2 MOD = 10**9 + 7 MOD_Farmer = 10**9+5 fact = [0] * SIZE inv = [0] * SIZE fact_inv = [0] * SIZE # prepare -------------------------------- inv[0] = 0 inv[1] = 1 fact[0] = fact[1] = 1 fact_inv[0] = fact_inv[1] = 1 for i in range( 2, SIZE ): inv[i] = MOD - (MOD//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...
s969206739
p04046
Accepted
mod=10**9+7 g1=[1,1] g2=[1,1] inverse=[0,1] h,w,a,b=map(int,input().split()) n=h+w for i in range(2,n+1): g1.append((g1[-1]*i)%mod) inverse.append((-inverse[mod % i]*(mod//i))%mod) g2.append((g2[-1]*inverse[-1])%mod) def cmb(n,r): return g1[n]*g2[r]*g2[n-r]%mod ans=0 while a<h and b<w: ans=(ans+cmb...
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...
s257430025
p04046
Accepted
h,w,a,b=map(int,input().split()) n_func=[None for _ in [0]*200001] n_func[0]=1 for i in range(1,200001): n_func[i]=(i*n_func[i-1])%(10**9+7) def inv_n(n,mod=10**9+7):return pow(n,mod-2,mod) def nCr(n,r,mod=10**9+7):return inv_n(n_func[n-r]*n_func[r]%mod,mod)*n_func[n]%mod cnt=0 for i in range(h-a): cnt=(cnt+nC...
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...
s396753934
p04046
Accepted
#!/usr/bin/env python3 #ABC42 D import sys import math import bisect sys.setrecursionlimit(1000000000) from heapq import heappush, heappop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools im...
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...
s572632984
p04046
Accepted
MOD=10**9+7 fact=[1] temp=1 for i in range(1,3*10**5+1): temp*=i temp%=MOD fact+=[temp] def bino(a,b): if a<b: return 0 up=fact[a] down=fact[a-b]*fact[b] return (up*pow(down,MOD-2,MOD))%MOD def find(H,W,A,B): temp=0 for x in range(1,H-A+1): temp+=bino(x+B-2,x-1)*bin...
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...
s887985046
p04046
Accepted
# coding: utf-8 # Your code here! SIZE=200001; MOD=10**9+7 #998244353 #ここを変更する SIZE += 1 inv = [0]*SIZE # inv[j] = j^{-1} mod MOD fac = [0]*SIZE # fac[j] = j! mod MOD finv = [0]*SIZE # finv[j] = (j!)^{-1} mod MOD inv[1] = 1 fac[0] = fac[1] = 1 finv[0] = finv[1] = 1 for i in range(2,SIZE): inv[i] = MOD - (MOD//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...
s111610382
p04046
Accepted
def modinv(a, m): #mod. m でのaの逆元 a^{-1}を計算する b = m u = 1 v = 0 while b: t = a//b a -= t * b a, b = b, a u -= t * v u, v = v, u u %= m if u < 0: u += m return u H, W, A, B = map(int, input().split()) MOD = 10 ** 9 + 7 #O(N) first = [] 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...
s204553810
p04046
Accepted
H,W,A,B=map(int,input().split()) N=H+W mod=10**9+7 factl=[1] for i in range(1,N+1): factl.append(factl[-1]*i%mod) invl=[pow(factl[-1],mod-2,mod)] for i in range(N,0,-1): invl.append(invl[-1]*i%mod) invl.reverse() def Comb(a,b): return factl[a]*invl[a-b]*invl[b] ans=0 for i in range(H-A): ans+=Comb(B+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...
s472442999
p04046
Accepted
import math def modinv(a,m): b = m u = 1 v = 0 while(b): t = a // b a -= t * b a,b = b,a u -= t * v u,v = v,u u %= m if u < 0: u += m return u inp = input().split(' ') inpint = [int(i) for i in inp] h = inpint[0] w = inpint[1] a = inpint[2] b = inpint[3] xfac = [0 for r in range(h+w-2)] xfac_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...
s529178804
p04046
Accepted
def frac_with_mod(a,m): outlist = [ 1 for i in range(a+1) ] for i in range(1,a+1): outlist[i] = (outlist[i-1] * i)% m return outlist frac_list = frac_with_mod(2*10**5,10**9+7) def comb_with_mod(a,b,m): global frac_list return ( frac_list[a+b-2] * pow(frac_list[a-1],m-2,m) * pow(frac_list[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...
s844835786
p04046
Accepted
H, W, A, B = list(map(int, input().split())) p = 1000000007 fac = [1] * (H + W + 1) x = 1 for i in range(1, H + W + 1): x *= i x %= p fac[i] = x ifac = [1] * (H + W + 1) x = fac[H + W] q = p - 2 while q > 0: if q & 1: ifac[H + W] *= x % p x *= x % p q >>= 1 for i in range(H + 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...
s637152001
p04046
Accepted
M = 1000000007 h, w, a, b = list(map(int, input().split())) def inv(k): return pow(k, M - 2, M) def comb(n, k): if n < k: return 0 elif k == 0: return 1 else: r = 1 for i in range(k): r = (r * ((n - i) * inv(k - i)) % M) % M return r ans = comb(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...
s028350294
p04046
Accepted
h, w, a, b = map(int, input().split()) MOD = 10 ** 9 + 7 f = [1] * 300005 for i in range(2, 300005): f[i] = (f[i - 1] * i) % MOD def comb(k, n): if n < k: return 0 if k == 0 or n == k: return 1 return (f[n] * pow(f[k], MOD - 2, MOD) * pow(f[n - k], MOD - 2, MOD)) % MOD ans = 0 for 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...
s215139442
p04046
Accepted
mod = 10**9 + 7 N = 200000 fact = [None] * (N+1) fact[0] = 1 for i in range(1, N+1): fact[i] = fact[i-1] * i % mod def comb(n, k): return fact[n] * pow(fact[k], mod-2, mod) * pow(fact[n-k], mod-2, mod) % mod H, W, A, B = map(int, input().split()) ans = 0 for b in range(B+1, W+1): tmp = comb(H-A+b-2, 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...
s025302990
p04046
Accepted
H, W, A, B = map(int, input().split()) MOD = 10 ** 9 + 7 fac = [1] inv = [1] for i in range(1, H+W+1) : fac.append(fac[-1] * i % MOD) inv.append(pow(fac[-1], MOD - 2, MOD)) ret = 0 for i in range(H-A) : ret += fac[i+B-1]*inv[i]*inv[B-1]*fac[H+W-i-B-2]*inv[H-i-1]*inv[W-B-1]%MOD ret %= MOD pri...
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...
s772888529
p04046
Accepted
import os import sys if os.getenv("LOCAL"): sys.stdin = open("_in.txt", "r") sys.setrecursionlimit(2147483647) INF = float("inf") IINF = 10 ** 18 MOD = 10 ** 9 + 7 H, W, A, B = list(map(int, sys.stdin.readline().split())) # dp = np.ones(W, dtype=int) # for h in range(1, H - A): # dp = dp.cumsum() % MOD # 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...
s965791230
p04046
Accepted
mod = 1000000007 H, W, A, B = map(int, raw_input().split()) factorial = [1] for n in xrange(1, H+W): factorial.append(factorial[n-1]*n%mod) def power(x, y): if y == 0 : return 1 elif y == 1 : return x % mod elif y % 2 == 0 : return power(x, y/2)**2 % mod else : return power(x,...
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...
s301480273
p04046
Accepted
h, w, a, b = map(int, input().split()) mod = 10**9+7 fac = [1] for n in range(1, h+w): fac.append(fac[n-1]*n%mod) def modpow(a,n,mod): r=1 while n>0: if n&1: r = r*(a%mod) a *= a%mod n >>= 1 return r invfac = [0] * (h+w) invfac[h+w-1] = modpow(fac[h+w-1], mod-2, mod) for n in range(h+w-2, -1, -1): invfac[...
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...
s602175149
p04046
Accepted
def mf(num,mod): ret=1 for i in range(1,num+1): ret=(ret*i)%mod return ret def rev(num,pow,mod): ret=1 while pow>0: if pow&1!=0: ret=(ret*num)%mod pow=pow>>1 num=(num*num)%mod return ret h,w,a,b=map(int,input().split()) mod=10**9+7 ans=[] s=0 tb=rev(mf(b,mod),mod-2,mod) tf=mf(b-1,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...
s943735466
p04046
Accepted
MOD = 10**9 + 7 MAX = int(2e5+1) def div(a, b): return a * pow(b, MOD-2, MOD) % MOD FACT = [1] * (MAX+1) for i in range(1, MAX+1): FACT[i] = (i * FACT[i-1]) % MOD INV = [1] * (MAX+1) INV[MAX] = div(1, FACT[MAX]) for i in range(MAX, 0, -1): INV[i-1] = (INV[i] * i) % MOD def main(): 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...
s815855023
p04046
Accepted
H, W, A, B = map(int, input().split()) MOD = 10 ** 9 + 7 N = 100 # 階乗 & 逆元計算 factorial = [1] inverse = [1] for i in range(1, H + W + 1): factorial.append(factorial[-1] * i % MOD) inverse.append(pow(factorial[-1], MOD - 2, MOD)) # 組み合わせ計算 def nCr(n, r): if n < r or r < 0: return 0 elif r == 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...
s833612910
p04046
Accepted
def main(): H, W, A, B = map(int, input().split()) H, W= H-1, W-1 DIV = 10**9+7 size = H+W+1 fact = [0]*size inverse = [0]*size inv_cal = [0]*size fact[:2] = [1, 1] inverse[:2] = [1, 1] inv_cal[:2] = [0, 1] for i in range(2, size): fact[i] = (fact[i-1]*i%DIV) inv_cal[i] = (-inv_cal[DIV%i]*(DIV//i))%DIV...
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...
s064393174
p04046
Accepted
def main(): H, W, A, B = map(int, input().split()) H, W= H-1, W-1 DIV = 10**9+7 size = H+W+1 fact = [0]*size inverse = [0]*size inv_cal = [0]*size fact[:2] = [1, 1] inverse[:2] = [1, 1] inv_cal[:2] = [0, 1] for i in range(2, size): fact[i] = (fact[i-1]*i%DIV) inv_cal[i] = (-inv_cal[DIV%i]*(DIV//i))%DIV...
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...
s651220120
p04046
Accepted
def cmb(a, b, fact, mod): return fact[a] * pow(fact[b], mod - 2, mod) * pow(fact[a - b], mod - 2, mod) % mod def main(): h, w, a, b = map(int, input().split()) mod = 10 ** 9 + 7 fact = [1] * (h + w + 1) for i in range(1, h + w + 1): fact[i] = (fact[i - 1] * i) % mod ans = 0 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...
s576785754
p04046
Accepted
def inpl(): return list(map(int, input().split())) H, W, A, B = inpl() MOD = 10**9 + 7 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 size = H+ W + 1 g1, g2, inverse = [0]*size, [0]*size, [0]*size g1[:2] = [1, 1] # 元テーブル g2[:2] = [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...
s957738754
p04046
Accepted
class combnk_mod(object): # pが素数かつaとpが互いに素であるとき # フェルマーの小定理より以下が成り立つ. # 1 / a = a ** (p - 2) (mod p) # これを使って (1 / k!) mod p を計算する. def __init__(self, maxn, p): self.maxn = maxn self.p = p self.x = [1] # 分母にあたる数 1 / n! mod p self.y = [1] # 分子にあたる数. n! mod p fo...
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...
s754756754
p04046
Accepted
H,W,A,B=map(int,input().split()) INF=10**9+7 x=[0]*(H+W-1) x[0]=1 for i in range(1,H+W-1): x[i]=(i*x[i-1])%INF y=[0]*(H+W-1) y[-1]=pow(x[-1],10**9+5,INF) for i in range(H+W-2,0,-1): y[i-1]=(y[i]*i)%INF ans=0 for i in range(B,W): j=H-A-1 ans+=(x[i+j]*y[i]*y[j])*(x[W-1-i+H-2-j]*y[H-2-j]*y[W-1-i]) 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...
s162359607
p04046
Accepted
mod=10**9+7 h,w,a,b=map(int,input().split()) F,I=[0]*(h+w+2),[0]*(h+w+2) def inv(n): return pow(n,mod-2,mod) F[0],F[1],I[0],I[1]=1,1,1,1 for i in range(2,h+w+2): F[i]=i*F[i-1]%mod I[i]=inv(F[i]) def c(a,b): return F[a+b]*I[a]*I[b]%mod ans=0 for i in range(b+1,w+1): ans+=(c(h-a-1,i-1)*c(a-1,w-i))%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...
s303710844
p04046
Accepted
import operator as op from functools import reduce MODULUS = 10**9 + 7 if __name__ == '__main__': [h, w, a, b] = map(int, input().split()) # Taken from https://atcoder.jp/contests/abc042/submissions/3178794 for learning purposes. factorial = [0] * (h+w) factorial[0] = 1 factorial[1] = 1 inver...
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...
s735263126
p04046
Accepted
H,W,A,B = map(int,input().split()) P=10**9+7 fac=[1]*(H+W) inv=[1]*(H+W) finv=[1]*(H+W) for n in range(2,H+W): fac[n]=fac[n-1]*n%P inv[n]=(-inv[P%n]*(P//n))%P finv[n]=finv[n-1]*inv[n]%P def comb(n,k):return ((fac[n]*finv[k]%P)*finv[n-k])%P ans=0 for i in range(1,min(W-B+1,H-A+1)): w=B+i-1 h=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...
s239425847
p04046
Accepted
H,W,A,B=map(int,input().split()) N=H+W+2 mod=10**9+7 table=[1]*(N+3) t=1 for i in range(1,N+3): t*=i t%=mod table[i]=t rtable=[1]*(N+3) t=1 for i in range(1,N+3): t*=pow(i,mod-2,mod) t%=mod rtable[i]=t ans=0 for i in range(H-A): t=table[B-1+i]*rtable[i]*rtable[B-1] s=table[W+H-B-i-2]*rta...
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...
s569141799
p04046
Accepted
#Combinationクラス class Combination: def __init__(self, n, MOD): self.fact = [1] for i in range(1, n + 1): self.fact.append(self.fact[-1] * i % MOD) self.inv_fact = [pow(self.fact[i] ,MOD - 2 ,MOD) for i in range(n + 1)] self.MOD = MOD def factorial(self, 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...
s478605185
p04046
Accepted
def read_input(): h, w, a, b = map(int, input().split()) return h, w, a, b # xの階乗 mod 10**9 + 7 について、1~nまでの結果を辞書にして返す def factorial_table(n): result = {0:1} curr = 1 acc = 1 modmax = (10**9) + 7 while curr <= n: acc *= curr acc %= modmax result[curr] = acc ...
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...
s491412173
p04046
Accepted
h,w,a,b=map(int,input().split()) mod=10**9+7 fact=[1]*(h+w+1) for i in range(1,h+w+1): fact[i]=(fact[i-1]*i)%mod def cmb(a,b): return fact[a]*pow(fact[b],mod-2,mod)*pow(fact[a-b],mod-2,mod)%mod ans=0 for i in range(b,w): ans+=cmb(h-a+i-1,i)*cmb(w-1-i+a-1,w-i-1)%mod print(ans%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...
s775764445
p04046
Accepted
from sys import exit H,W,A,B = [int(n) for n in input().split()] MOD = 10**9+7 NUM = 2*10**5 fact=[1]*(NUM+1) factinv=[1]*(NUM+1) for i in range(1,NUM+1): fact[i]=(fact[i-1]*i)%MOD factinv[NUM]=pow(fact[NUM],MOD-2,MOD) for i in range(NUM,0,-1): factinv[i-1]=(factinv[i]*i) % 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...
s623347379
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: return 0 x = fact[n] x *= fact_inv[k] x %= MOD x *= 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...
s006880260
p04046
Accepted
h, w, a, b = [int(item) for item in input().split()] MOD = 10**9 + 7 n = h + w def mod_pow(x, n): ans = 1 while(n != 0): if n & 1: ans = ans * x % MOD x = x * x % MOD n = n >> 1 return ans fac = [1] + [0] * n fac_inv = [1] + [0] * n for i in range(1, n+1): fac[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...
s034278573
p04046
Accepted
import sys def comb(n, r, MOD, factrial, fact_inv): if n < 0 or r < 0 or n < r: return 0 else: return (factrial[n] * fact_inv[r] * fact_inv[n-r]) % MOD def main(): input = sys.stdin.readline H, W, A, B = map(int, input().split()) MOD = 10**9 + 7 n = H + W - 2 factrial = ...
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...
s860364454
p04046
Accepted
from functools import reduce import math memo = [] memo_inv = [] MOD = 10**9+7 def get_factorial(i): return memo[i] def get_factorial_inv(i): return memo_inv[i] def nCr(n, r): return get_factorial(n) * get_factorial_inv(n-r) * get_factorial_inv(r) def main(): # 一文字のみを読み込み # s = input().rstr...
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...
s526215955
p04046
Accepted
m=10**9+7 h,w,a,b=map(int,input().split()) d=c=1 for i in range(h-1): d=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 d+=c print(d%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...
s971022354
p04046
Accepted
def mod_inv(n: int, mod: int)->int: b, u, v = mod, 1, 0 while b > 0: t = n // b n -= t * b u -= t * v n, b = b, n u, v = v, u return (u+mod) % mod def comb(r: int, c: int, mod: int) -> int: if c < 0 or r < c: raise Exception('invalid r={}, c={}'.forma...
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...
s680029994
p04046
Accepted
from sys import stdin import sys sys.setrecursionlimit(1000000) mod = 10 ** 9 + 7 input = stdin.readline H, W, A, B = [int(x) for x in input().rstrip().split()] factorial = [1] for i in range(1, H+W): factorial.append(factorial[i-1] * i % mod) def power(x, y): if y == 0: return 1 elif y == 1: return x % 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...
s032132084
p04046
Accepted
#!/usr/bin/env python3.4 # -*- coding: utf-8 -*- # arc058_b # input H, W, A, B = map(int, input().split()) mod = 1000000007 # fermat N = 0 fac = [1] inv = [1] def mypow(a, b): return _mypow(a, a, b) def _mypow(p, a, b): if b == 1: return p n = (p*p) % mod c, r = divmod(b, 2) if r == 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...
s548073452
p04046
Accepted
H, W, A, B = list(map(int, input().split())) # 事前計算 + 演算ごとに mod する def solve(): # 組合せの計算用に階乗を事前計算しておく MOD = 10 ** 9 + 7 FACT = [0] * (H + W + 1) INV_FACT = [0] * (H + W + 1) # 逆元. 組合せの計算ごとにMODを取るため FACT[0], INV_FACT[0] = 1, 1 for i in range(1, (H + W + 1)): FACT[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...
s671135255
p04046
Accepted
import math H, W, A, B = map(int, input().split()) MOD = 10 ** 9 + 7 factorial = [1] inv_factorial = [1] for i in range(1, H+W+1): factorial.append(factorial[-1] * i % MOD) inv_factorial.append(pow(factorial[-1], MOD-2, MOD)) def f(h, w): return (factorial[h+w-2] * inv_factorial[h-1] * inv_factorial[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...
s960498477
p04046
Accepted
# coding: UTF-8 import numpy as np MOD = int(1e+9+7) H, W, A, B = map(int, input().split()) fact = [1] for i in range(1, W+H-1): fact.append((fact[-1]*i) % MOD) ifact = [pow(fact[-1], MOD-2, MOD)] for i in reversed(range(1, W+H-1)): ifact.append((ifact[-1]*i) % MOD) ifact.reverse() def comb(n, r): 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...
s473049594
p04046
Accepted
import sys from collections import deque import copy import bisect import math def get_read_func(fileobject): if fileobject == None : return raw_input else: return fileobject.readline def power_func(a,b,p): if b==0: return 1 if b%2==0: d=power_func(a,b//2,p) return d*d %p if b%2==...
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...
s428810004
p04046
Accepted
h, w, a, b = map(int, input().split()) MOD = 10 ** 9 + 7 class ModCmb: def __init__(self, size): self.inv = [1] * (size + 1) self.fact = [1] * (size + 1) temp_inv = [1] * (size + 1) for i in range(2, size + 1): temp_inv[i] = ( -(MOD // i) * temp_inv[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...
s602098093
p04046
Accepted
#!usr/bin/env python3 from collections import defaultdict from heapq import heappush, heappop import sys import math import bisect import random def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return list(map(list, sys.stdin.readline().split())) def 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...
s727928694
p04046
Accepted
#!usr/bin/env python3 from collections import defaultdict from heapq import heappush, heappop import sys import math import bisect import random def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return list(map(list, sys.stdin.readline().split())) def 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...
s921971259
p04046
Accepted
#!usr/bin/env python3 from collections import defaultdict from heapq import heappush, heappop import sys import math import bisect import random def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return list(map(list, sys.stdin.readline().split())) def 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...
s762939325
p04046
Accepted
H,W,A,B = map(int, input().split()) mod = 10**9+7 fact = [1] for i in range(1, H+W+1): fact.append ( fact[-1] * i % mod) inv_fact = [0] * (H+W+1) inv_fact[H+W] = pow(fact[H+W], mod-2, mod) for i in range(H+W, 1, -1): inv_fact[i-1] = inv_fact[i] * i % mod inv_fact[0] = 1 def C(a,b): if a <= 0 or b < 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...
s433747861
p04046
Accepted
Q = 10**9+7 def getInv(N):#Qはmod inv = [0] * (N + 1) inv[0] = 1 inv[1] = 1 for i in range(2, N + 1): inv[i] = (-(Q // i) * inv[Q%i]) % Q return inv modfunctional = [1]*(2*10**5+1) modinv = getInv(10**5+1) modinvfunctional = [1]*(10**5+1) for i in range(10**5): modinvfunctional[i+1] = (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...
s415150880
p04046
Accepted
class Factorial: def __init__(self,n,mod): self.f=[1] for i in range(1,n+1): self.f.append(self.f[-1]*i%mod) self.i=[pow(self.f[-1],mod-2,mod)] for i in range(1,n+1)[::-1]: self.i.append(self.i[-1]*i%mod) self.i.reverse() def factorial(self,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...
s214656036
p04046
Accepted
h,w,a,b=map(int,input().split()) mod=10**9+7 n=h+w+1 fc,inv=[1]*n,[1]*n for i in range(1,n): fc[i]=i*fc[i-1]%mod inv[n-1]=pow(fc[n-1],mod-2,mod) for i in range(n-1,0,-1): inv[i-1]=inv[i]*i%mod f=lambda a,b:fc[a+b]*inv[a]*inv[b]%mod v=0 for i in range(b,w): v+=f(h-a-1,i)*f(a-1,w-i-1)%mod print(v%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...
s491323396
p04046
Accepted
H, W, A, B = map(int, input().split()) mod = 10 ** 9 + 7 # 階乗 & 逆元計算 factorial = [1] inverse = [1] for i in range(1, H + W + 1): factorial.append(factorial[-1] * i % mod) inverse.append(pow(factorial[-1], mod-2, mod)) # 組み合わせ計算 def nCr(n, r): if n < r or r < 0: return 0 elif r == 0: 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...
s817940056
p04046
Accepted
H, W, A, B = map(int, input().split()) mod = 10 ** 9 + 7 ans = 0 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 combination(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...
s160453898
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] * Y[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...
s524441006
p04046
Accepted
h, w, a, b = map(int, input().split()) mod = 10 ** 9 + 7 MAX_N = 2 * 10 ** 5 factorial = [1] * MAX_N #事前に階上テーブルを用意 def calc_factorial(): for i in range(1, MAX_N): factorial[i] = i * factorial[i - 1] % mod def comb(n, k): a = factorial[n] % mod b = (factorial[k] * factorial[n - k]) % mod b_ = 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...
s971526659
p04046
Accepted
H, W, A, B = map(int, input().split()) h = {} p = 10**9+7 q = p - 2 for x in range(H+W-1): if h.get(x-1): a = (x * h[x-1][0]) % p else: a = 1 b = pow(a,q,p) h[x] = (a,b) def C(n, r): return h[n][0] * h[r][1] * h[n-r][1] ans = 0 for i in range(B, W): ans += C(i+H - A - 1, i) * C...
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...
s750423043
p04046
Accepted
H, W, A, B = map(int, input().split()) h = {} p = 10**9+7 q = p - 2 for x in range(H+W-1): if h.get(x-1): a = (x * h[x-1][0]) % p else: a = 1 b = pow(a,q,p) h[x] = (a,b) def C(n, r): return h[n][0] * h[r][1] * h[n-r][1] ans = 0 for i in range(B, W): ans += C(i+H - A - 1, i) * C...
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...
s922921200
p04046
Accepted
mod = 10**9+7 h, w, a, b = map(int, input().split()) n = h+w-2 ans = 0 fac = [1]*(n+1) inv = [1]*(n+1) for i in range(1, n+1): fac[i] = i*fac[i-1] % mod for i in range(1, n+1): inv[i] = pow(fac[i], mod-2, mod) def func(x, y): m = fac[x+y]*inv[x]*inv[y]%mod return m for x in range(b, w): 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...
s756476304
p04046
Accepted
H,W,A,B = map(int,input().split()) def init_fact(n,mod): fact,finv,inv = [1]*n,[1]*n,[1]*n for i in range(2,n): fact[i] = (fact[i-1]*i) % mod inv[i] = mod - inv[mod%i] * (mod//i)%mod finv[i] = finv[i-1] * inv[i] % mod return (fact,finv,inv) def nCr(n,r,mod,fact,finv): if 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...
s843656330
p04046
Accepted
H, W, A, B = map(int, input().split()) answer = 0 mod = 1000000007 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: 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...
s695264505
p04046
Accepted
H, W, A, B = (int(i) for i in input().split()) def power(a, b): if b == 0: return 0 elif b == 1: return a % 1000000007 elif b % 2 == 0: return (power(a, b//2) ** 2) % 1000000007 else: return (power(a, b//2) ** 2 * a) % 1000000007 def divide(a, b): return (a * power(b, 1000000005)) % 1000000007 #階乗の逆元...
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...
s442498448
p04046
Accepted
H, W, A, B = map(int, input().split()) ans = 0 MOD = 10**9 + 7 N = H + W - 2 fac = [1] * (N+1) inv = [1] * (N+1) # 階乗 for i in range(1, N+1): fac[i] = i * fac[i - 1] % MOD # 普通の逆元テーブル for i in range(1, N+1): inv[i] = pow(fac[i], MOD-2, MOD) def f(x, y): ans = fac[x + y] * inv[x] * inv[y] % 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...
s090395446
p04046
Accepted
H, W, A, B = map(int, input().split()) ans = 0 MOD = 10**9 + 7 N = H + W - 2 fac = [1] * N inv = [1] * N # 階乗 for i in range(1, N): fac[i] = (fac[i - 1] * i) % MOD # 高速な逆元テーブル 最初にN-1を求めておくことであとはiをかけるだけで残りの逆元が算出できる inv[N - 1] = pow(fac[N - 1], MOD - 2, MOD) for i in range(N - 1, 0, -1): inv[i - 1] = (inv[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...
s717382803
p04046
Accepted
H, W, A, B = map(int, input().split()) ans = 0 MOD = 10**9 + 7 N = H + W - 2 fac = [1] * N inv = [1] * N # 階乗 for i in range(1, N): fac[i] = (fac[i - 1] * i) % MOD # 逆元 inv[N - 1] = pow(fac[N - 1], MOD - 2, MOD) for i in range(N - 1, 0, -1): inv[i - 1] = (inv[i] * i) % MOD def f(x, y): ans = fac[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...
s237165575
p04046
Accepted
H,W,A,B=map(int,input().split()) mod=10**9+7 n=H+W INV=[None]*(n+1)#1/aのリストを予め作っておく. for i in range(1,n+1): INV[i]=pow(i,mod-2,mod) k=H+W-2 n=H-1 Combi1=[None]*(k+1)#Combi[i]=iCnを表す.kは必要な分だけ. Combi1[n]=1 for i in range(n+1,k+1): Combi1[i]=Combi1[i-1]*i*INV[i-n] %mod k=H+B-2 n=B-1 Combi2=[None]*(k+1)#Combi[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...
s914502816
p04046
Accepted
mod=10**9+7 H,W,A,B=map(int,input().split()) Factorial=[1]*(H+W+1) for i in range(1,H+W+1): Factorial[i]=Factorial[i-1]*(i)%mod def power(x,y): if y==0: return 1 elif y==1: return x%mod elif y%2==0: return power(x,y//2)**2%mod else: return (power(x,y//2)**2)*x%mod inverseFactorial=[1]*(H+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...
s961135878
p04046
Accepted
K = 10 ** 9 + 7 def pow_K(x, n): if n == 0: return 1 else: return (pow_K(x, n // 2) ** 2 * x ** (n % 2)) % K H, W, A, B = map(int, input().split()) fact = [0 for i in range(H+W-1)] fact[0] = 1 for i in range(H+W-2): fact[i + 1] = fact[i] * (i+1) % K fact_inv = [0 for i in range(H+W-1)] fact_inv[H+W-2] ...
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...
s613130251
p04046
Accepted
H, W, A, B = map(int, input().split()) M = 10 ** 5 + 5 M *= 2 fact = [0] * M rfact = [0] * M fact[0] = 1 MOD = 10 ** 9 + 7 for i in range(1, M): fact[i] = fact[i - 1] * i % MOD rfact[M - 1] = pow(fact[M - 1], MOD - 2, MOD) for i in range(M - 2, -1, -1): rfact[i] = rfact[i + 1] * (i + 1) % MOD def comb(n, 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...
s790245245
p04046
Accepted
def mod_inv(inv,a,m): i=a if inv.get(a,0)!=0: return inv[a] e=m-2 tmp=1 while e!=1: if e%2==1: tmp*=a tmp%=m a*=a a%=m e//=2 a*=tmp a%=m inv[i]=a return a def factrial(fact,a,m): for i in range(1,a+1): 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...
s902637464
p04046
Accepted
import math MOD = 10 ** 9 + 7 H, W, A, B = map(int, input().split()) maxf = H + W f, invf = [1] * maxf, [1] * maxf for i in range(1, maxf): f[i] = i * f[i - 1] % MOD invf[maxf - 1] = pow(f[maxf - 1], MOD - 2, MOD) for i in range(maxf - 1, 0, -1): invf[i - 1] = invf[i] * i % MOD comb = lambda a, b: f[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...
s233413978
p04046
Accepted
def gcd(a, b): while b: a, b = b, a % b return a def egcd(a, b): (x, lastx) = (0, 1) (y, lasty) = (1, 0) while b != 0: q = a // b (a, b) = (b, a % b) (x, lastx) = (lastx - q * x, x) (y, lasty) = (lasty - q * y, y) return (lastx, lasty, a) # ax ≡ 1 (mod m) def 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...
s106203428
p04046
Accepted
from collections import defaultdict, Counter from itertools import product, groupby, count, permutations, combinations from math import pi, sqrt from collections import deque from bisect import bisect, bisect_left, bisect_right from string import ascii_lowercase from functools import lru_cache import sys sys.setrecursi...
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...
s946115370
p04046
Accepted
MAX = 510000 MOD = 1000000007 fac = [0] * MAX finv = [0] * MAX inv = [0] * MAX def comb_init(): 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 % MOD inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD finv[i] = finv[i - 1] * 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...
s417702275
p04046
Accepted
iH,iW,iA,iB = [int(x) for x in input().split()] iD = 10**9+7 #法 iLBoxW=iB-1 iLBoxH=iH-iA-1 iRBoxW=iW-iB-1 iRBoxH=iH-1 #iMax = iH+iW-2 iMax = max(iLBoxW+iLBoxH,iRBoxW+iRBoxH) #nCr = n!/r!(n-r)! #二分累乗法 iDを法として def fBiPow(iX,iN,iD): iY = 1 while iN > 0: if iN % 2 == 0: iX = iX * iX % iD ...
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...
s850465721
p04046
Accepted
iH,iW,iA,iB = [int(x) for x in input().split()] iD = 10**9+7 #法 #初等整数論勉強して解説通りキッチリ実装したった #二分累乗法 iDを法として def fBiPow(iX,iN,iD): iY = 1 while iN > 0: if iN % 2 == 0: iX = iX * iX % iD iN = iN // 2 else: iY = iX * iY % iD iN = iN - 1 return iY #...
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...
s976535576
p04046
Accepted
# -*- coding: utf-8 -*- H,W,A,B = map(int, input().split()) mod = (10 ** 9 + 7) # 予め組み合わせ計算に必要な階乗と逆元のテーブルを作っておく factorial = [1] * (H+W) factorial[0] = 1 factorial[1] = 1 for i in range(2,H+W): factorial[i] = factorial[i-1] * i % mod inverse = [1] * (H+W) # フェルマーの小定理から(x! ** mod-2 % mod == x! ** -1 % mod) # 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...
s668782399
p04046
Accepted
# -*- coding: utf-8 -*- H,W,A,B = map(int, input().split()) mod = (10 ** 9 + 7) # 予め組み合わせ計算に必要な階乗と逆元のテーブルを作っておく factorial = [0] * (H+W) factorial[0] = 1 factorial[1] = 1 inverse = [0] * (H+W) inverse[0] = 1 inverse[1] = 1 for i in range(2,H+W): factorial[i] = factorial[i-1] * i % mod # フェルマーの小定理から(x! ** mod-2...
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...
s565161318
p04046
Accepted
h,w,a,b=map(int, input().split()) n=h+w-2 mod=10**9+7 fc,inv=[1]*n,[1]*n for i in range(1,n): fc[i]=i*fc[i-1]%mod inv[n-1]=pow(fc[n-1],mod-2,mod) for i in range(n-1,0,-1): inv[i-1]=inv[i]*i%mod f=lambda a,b:fc[a+b]*inv[a]*inv[b]%mod v=0 for x in range(b,w): v+=f(x,h-a-1)*f(w-1-x,a-1)%mod print(v%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...
s829026072
p04046
Accepted
H, W, A, B = map(int, input().split()) mod = 10**9 + 7 N = H + W - 2 # 階乗 fac = [1] * N for i in range(1, N): fac[i] = (fac[i - 1] * i) % mod # 逆元 inv = [1] * N inv[N - 1] = pow(fac[N - 1], mod - 2, mod) for i in range(N - 1, 0, -1): inv[i - 1] = (inv[i] * i) % mod def f(x, y): res = fac[x + y] * inv[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...
s718080819
p04046
Accepted
H, W, A, B = map(int, input().split()) mod = 10 ** 9 + 7 # 階乗 fac = [1] * (H + W - 2) # 逆元 inv = [1] * (H + W - 2) for i in range(1, H + W - 2): fac[i] = (fac[i - 1] * i) % mod inv[i] = pow(fac[i], mod - 2, mod) def f(x, y): res = fac[x + y] * inv[x] * inv[y] return res % mod ans = 0 for x 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...
s770652618
p04046
Accepted
from collections import defaultdict,deque import sys,heapq,bisect,math,itertools,string,queue,datetime sys.setrecursionlimit(10**8) INF = float('inf') mod = 10**9+7 eps = 10**-7 def inpl(): return list(map(int, input().split())) def inpl_s(): return list(input().split()) H,W,A,B=inpl() ans = 0 MAX = H+W fac = [1]*(MA...
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...
s952616122
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...
s491184318
p04046
Accepted
# nの逆元のリスト def inv_mod(n:int, mod:int) -> list: inv = [0,1] for i in range(2,n+1): inv.append(mod - ((mod//i)*inv[mod%i]) % mod) return inv # nの階乗のリスト def fact(n:int, mod:int) -> list: fac = [1,1] res = 1 for i in range(2,n+1): res = res*i%mod fac.append(res) ...
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...
s875460692
p04046
Accepted
H,W,A,B = map(int,input().split()) N = H+W+10 MOD = 10**9+7 fac = [1,1] + [0]*N finv = [1,1] + [0]*N inv = [0,1] + [0]*N for i in range(2,N+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 ncr(n,r): if n < r: return 0 if n < 0 or r < 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...
s966300455
p04046
Accepted
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from pprint import pprint from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_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...
s030789723
p04046
Accepted
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from pprint import pprint from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_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...
s885713461
p04046
Accepted
H, W, A, B = map(int, input().split()) m = 10**9 + 7 import functools @functools.lru_cache(maxsize=None) def cr(c, r): return fc[c + r] * ic[c] * ic[r] % m fc = [1] * (H + W) for i in range(2, H+W): fc[i] = fc[i - 1] * i % m ic = [pow(x, m-2, m) for x in fc] ans = 0 for c in range(B, W): ans += cr(c, 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...
s524232114
p04046
Accepted
# nの逆元のリスト def inv_mod(n:int, mod:int) -> list: inv = [0,1] for i in range(2,n+1): inv.append(mod - ((mod//i)*inv[mod%i]) % mod) return inv # nの階乗のリスト def fact(n:int, mod:int) -> list: fac = [1,1] res = 1 for i in range(2,n+1): res = res*i%mod fac.append(res) ...
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...
s423917404
p04046
Accepted
H, W, A, B = map(int, input().split()) mod = 10**9 + 7 fact = [1] * (H + W - 1) invfact = [1] * (H + W - 1) for i in range(1, H + W - 1): fact[i] = fact[i - 1] * i % mod for i in range(1, H + W - 1): invfact[i] = pow(fact[i], mod-2, mod) def nCr(n,r): return fact[n] * invfact[r] * invfact[n-r] 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...
s927199611
p04046
Accepted
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 Fi = [pow(f, p - 2, p) for f in F] def fac(a, b): a = F[a + b] * Fi[a] * Fi[b] return a % p if H - A < B: ans = 0 for h in range(H - A): ans += fac(h, B - 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...