submission_id
string
problem_id
string
status
string
code
string
input
string
output
string
problem_description
string
s942681697
p04046
Accepted
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines MOD = 10**9+7 fac = [1, 1] f_inv = [1, 1] inv = [0, 1] def modcmb(n, r, mod): if n < 0 or r < 0 or r > n: return 0 return fac[n] * f_inv[r] * f_inv[n-r] % mod def main(): H,W,A,B = map(int, readline()...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s090963840
p04046
Accepted
import math MOD = 10**9+7 def xgcd(a, b): x0, y0, x1, y1 = 1, 0, 0, 1 while b != 0: q, a, b = a // b, b, a % b x0, x1 = x1, x0 - q * x1 y0, y1 = y1, y0 - q * y1 return a, x0, y0 def modinv(a): g, x, y = xgcd(a, MOD) return x % MOD fact = [1] * 200100 for i 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...
s282114164
p04046
Accepted
H, W, A, B = map(int, input().split()) MOD = 10 ** 9 + 7 i = H - A - 1 j = B # 階乗とその逆元を事前計算する (O(N)) # finv[0] := 0の階乗の逆元 def factorial_and_inv(n, mod=10 ** 9 + 7): f = [1] for n in range(1, n): f.append(f[n - 1] * n % mod) finv = [0] * n finv[n - 1] = pow(f[n - 1], mod - 2, mod) for n in...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s182937985
p04046
Accepted
#modの掛け算 def modmal(a,b,mod): #a*bをmodを法にして求める return a * b % mod #modの割り算 def moddiv(a,b,mod): #a/bをmodを法にして求める return (a * pow(b,mod-2)) % mod #逆元 def inverse(a,mod): #aのmodを法にした逆元を返す return pow(a,mod-2) #modのn!と、n!の逆元を格納したリストを返す(拾いもの) #factorialsには[1, 1!%mod , 2!%mod , 6!%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...
s654621568
p04046
Accepted
# coding: utf-8 # Your code here! h,w,a,b=map(int,input().split()) MOD=10**9+7 fac=[0]*2*10**5 finv=[0]*2*10**5 inv=[0]*2*10**5 fac[0]=fac[1]=1 finv[0]=finv[1]=1 inv[1]=1 for i in range(2,2*10**5): fac[i]=(fac[i-1]*i)%MOD inv[i]=MOD-inv[MOD%i]*(MOD//i)%MOD finv[i]=finv[i-1]*inv[i]%MOD def COM(n,k): if 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...
s606857002
p04046
Accepted
class Combination(): def __init__(self,n,mod): self.mod = mod self.factorial = [0 for _ in range(n+1)] self.inv = [0 for _ in range(n+1)] self.factorial[0] = 1 self.inv[0] = 1 for i in range(n): self.factorial[i+1] = self.factorial[i]*(i+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...
s078462178
p04046
Accepted
def cmb(n, r, mod): if ( r < 0 or r > n ): return 0 r = min(r, n - r) return g1[n] * g2[r] * g2[n - r] % mod MOD = 10 ** 9 + 7 #出力の制限 N = 10 ** 5 * 2 + 1 g1 = [1, 1] # 元テーブル g2 = [1, 1] #逆元テーブル inverse = [0, 1] #逆元テーブル計算用テーブル for i in range(2, N + 1 ): g1.append((g1[-1] * i) % MOD) inverse.append((-in...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s920292132
p04046
Accepted
MOD=10**9+7 class ModInt: def __init__(self, x): self.x = x % MOD def __str__(self): return str(self.x) __repr__ = __str__ def __add__(self, other): return ( ModInt(self.x + other.x) if isinstance(other, ModInt) else ModInt(self.x + other) ) ...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s364863027
p04046
Accepted
def nCr(n, r, mod): if r < 0 or n < r: return 0 r = min(r, n - r) return fact[n] * factinv[r] * factinv[n - r] % mod mod = 10 ** 9 + 7 N = 10 ** 6 fact = [1, 1] factinv = [1, 1] inv = [0, 1] for i in range(2, N + 1): fact.append((fact[-1] * i) % mod) inv.append((-inv[mod % i] * (mod // i)...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s149901092
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 + 2): 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...
s131034170
p04046
Accepted
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(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...
s687074406
p04046
Accepted
fact = [1] invfact = [1] mod = 10 ** 9 + 7 h, w, a, b = map(int, input().split()) for i in range(1, h+w+1): fact.append((fact[-1] * i) % mod) invfact.append(pow(fact[i], mod - 2, mod)) ans = 0 for i in range(b, w): ans += (fact[h - a - 1 + i] * invfact[h - a - 1] * invfact[i]) * \ (fact[a - 2 + 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...
s397708697
p04046
Accepted
h,w,a,b = map(int,input().split()) MOD = 1000000007 fac = [1] inv = [1] for i in range(1,200010): fac.append(fac[i-1]*i%MOD) inv.append(pow(fac[i],MOD-2,MOD)) ans = 0 for i in range(b+1,w+1): ans += fac[h-a+i-2]*inv[h-a-1]*inv[i-1]*fac[a+w-i-1]*inv[a-1]*inv[w-i]%MOD ans %= MOD print(ans)
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s836326087
p04046
Accepted
def cmb(n, r, mod): if ( r<0 or r>n ): return 0 r = min(r, n-r) return g1[n] * g2[r] * g2[n-r] % mod mod = 10**9+7 #出力の制限 N = 10**6+3 g1 = [1, 1] # 元テーブル g2 = [1, 1] #逆元テーブル inverse = [0, 1] #逆元テーブル計算用テーブル for i in range( 2, N + 1 ): g1.append( ( g1[-1] * i ) % mod ) inverse.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...
s150935219
p04046
Accepted
H, W, A, B = map(int, input().split()) mod = int(1e+9 + 7) p = mod - 2 X, Y = H-A, W-B L = [] while p != 0: L = [p%2] + L[:] p //= 2 S = 0 fL = [1] invfL = [] for i in range(H+W): fL.append(((i+1)*fL[i])%mod) for i in range(H): invi = 1 for j in range(len(L)): if L[j] == 1: invi *= fL[i] invi ...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s237685529
p04046
Accepted
H,W,A,B=map(int,input().split()) def extgcd(a,b): r = [1,0,a] w = [0,1,b] while w[2]!=1: q = r[2]//w[2] r2 = w w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]] r = r2 w = w2 #[x,y] return [w[0],w[1]] def mod_inv(a,m): x = extgcd(a,m)[0] return (m+x%m)%m def ...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s041217943
p04046
Accepted
from heapq import heappush,heappop,heapify from collections import deque,defaultdict,Counter import itertools from itertools import permutations,combinations import sys import bisect import string import math import time import random def I(): return int(input()) def MI(): return map(int,input().split()) def LI...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s257904792
p04046
Accepted
H, W, A, B = map(int,input().split()) MOD = 10**9 + 7 def prepare(n, MOD): # 1! - n! の計算 f = 1 factorials = [1] # 0!の分 for m in range(1, n + 1): f *= m f %= MOD factorials.append(f) # n!^-1 の計算 inv = pow(f, MOD - 2, MOD) # n!^-1 - 1!^-1 の計算 invs = [1] * (n + 1) ...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s052558038
p04046
Accepted
def nCr(n, r): global fact, inv, MOD return (fact[n] * inv[n-r] * inv[r]) % MOD MOD = 1000000007 MAX = 200001 h, w, a, b = map(int, input().split()) fact = [1 for i in range(MAX)] inv = [1 for i in range(MAX)] for i in range(1, MAX): fact[i] = (fact[i-1] * i) % MOD inv[i] = pow(fact[i], MOD-2, MOD) ans = 0 for...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s454560131
p04046
Accepted
h,w,a,b = map(int, input().split()) mod = 10**9 + 7 n = 10**5 * 2 + 1 fact = [1]*(n+1) rfact = [1]*(n+1) r = 1 for i in range(1, n+1): fact[i] = r = r * i % mod rfact[n] = r = pow(fact[n], mod-2, mod) for i in range(n, 0, -1): rfact[i-1] = r = r * i % mod # nPk (mod MOD) を求める def perm(n, k): return fact[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...
s383570485
p04046
Accepted
mod = 10**9+7 mod2 = 998244353 rng = 200001 fctr = [1] finv = [1] for i in range(1,rng): fctr.append(fctr[-1]*i%mod) for i in range(1,rng): finv.append(pow(fctr[i],mod-2,mod)) def cmb(n,k): if n<0 or k<0: return 0 else: return fctr[n]*finv[n-k]*finv[k]%mod h,w,a,b = map(int, input().spli...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s533006367
p04046
Accepted
h,w,a,b = map(int,input().split()) mod = 10 ** 9 + 7 def inv(a,mod): r = [1,0,a] w = [0,1,mod] while w[2]!=1: q = r[2]//w[2] r_new = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]] r = w w = r_new x,y = w[0],w[1] # a*x+y*mod = 1 return (mod+x%mod)%mod max_num = 2*10**5+1 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...
s371080943
p04046
Accepted
h, w, a, b = map(int, input().split()) N = h + w 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 mod = 10 ** 9 + 7 factorial = [1] for i in range(1, N): 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...
s345320008
p04046
Accepted
from array import * import time h, w, a, b = map(int, input().split(' ')) MOD = 10**9 + 7 MAX = max(h+w-a-1, a+w) def modpow(a, b): res = 1 while b: if (b & 1): res = (res * a) % MOD a = (a * a) % MOD b >>= 1 return res def nCr(n, r): if r == 0 or 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...
s710652752
p04046
Accepted
mod = int(1e9+7) def exgcd(a, b, arr): if b == 0: arr.clear() arr.append(1) arr.append(0) return a else: d = exgcd(b, a % b, arr) x = arr[1] y = arr[0] - a//b * arr[1] arr[0] = x arr[1] = y return d def Inv(a): arr = [] ...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s374244038
p04046
Accepted
mod = 10 ** 9 + 7 H, W, A, B = map(int, input().split()) fact = [-1] * (H + W + 1) fact[0] = 1 fact[1] = 1 for x in range(2, H + W + 1): fact[x] = x * fact[x - 1] % mod invs = [-1] * (H + W + 1) invs[H + W] = pow(fact[H + W], mod - 2, mod) for x in range(H + W - 1, 0, -1): invs[x] = invs[x + 1] * (x + 1) % m...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s480133783
p04046
Accepted
import sys MOD = 10 ** 9 + 7 def make_table(n=10**6, p=10**9+7): fac = [None] * (n + 1) fac[0] = 1 ifac = fac.copy() for i in range(1, n + 1): fac[i] = fac[i-1] * i % p ifac[n] = pow(fac[n], p - 2, p) for i in range(n-1, 0, -1): ifac[i] = ifac[i+1] * (i + 1) % p return 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...
s261982646
p04046
Accepted
h,w,a,b = map(int,input().split()) #入力 mod = 10**9+7 #前計算 f[i] = i! f=[1] for i in range(h+w): f.append(f[i]*(i+1)%mod) #C(n,r,p) = ( n! * r!^(p-2) * (n-r)!^(p-2) )%p #pythonだとpow()で二分累乗法が使える def comb(n, r, p): return f[n] * pow(f[r], p-2, p) * pow(f[n-r], p-2, p) % p #紫点ごとに調べる ans=0 for i 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...
s324373899
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] *...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s212120213
p04046
Accepted
import sys h, w, a, b = [int(i) for i in sys.stdin.readline().split()] dic = dict() MOD = 10**9+7 def nCr(n, r, mod=MOD): if ( r<0 or r>n ): return 0 r = min(r, n-r) return g1[n] * g2[r] * g2[n-r] % mod mod = 10**9+7 #出力の制限 N = 10**6 g1 = [1, 1] # 元テーブル g2 = [1, 1] #逆元テーブル inverse = [0, 1] #逆元テーブル...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s730117021
p04046
Accepted
#ABC042D H, W, A, B = map(int, input().split()) mod=10**9+7 N=H+W+1 bikkuri=[0 for i in range(N)] bikkuri[0]=1 for i in range(1,N): bikkuri[i] = (i * bikkuri[i-1])%mod gyaku=[0 for i in range(N)] gyaku[0]=1 for i in range(1, N): gyaku[i]=pow(bikkuri[i], mod-2, mod) def comb(n,r): return bikkuri[n]*gyaku[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...
s383741772
p04046
Accepted
H,W,A,B=map(int,input().split()) def cmb(n, r, mod): if ( r<0 or r>n ): return 0 r = min(r, n-r) return g1[n] * g2[r] * g2[n-r] % mod mod = 10**9+7 #出力の制限 N = 10**6 g1 = [1, 1] # 元テーブル g2 = [1, 1] #逆元テーブル inverse = [0, 1] #逆元テーブル計算用テーブル for i in range( 2, N + 1 ): g1.append( ( g1[-1] * i ) % ...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s738907900
p04046
Accepted
def cmb(n, r, mod): if ( r<0 or r>n ): return 0 r = min(r, n-r) return g1[n] * g2[r] * g2[n-r] % mod h,w,a,b = map(int,input().split()) ans = 0 mod = 10**9+7 #出力の制限 N = h+w+1 g1 = [1, 1] # 元テーブル g2 = [1, 1] #逆元テーブル inverse = [0, 1] #逆元テーブル計算用テーブル for i in range( 2, N + 1 ): g1.append( ( g1[-1...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s238223853
p04046
Accepted
h,w,a,b=map(int,input().split()) ans = 0 mod = 10**9 + 7 fac = [1] * (h+w+1) inv = [1] * (h+w+1) for i in range(1,h+w): fac[i] = (fac[i-1] * i)%mod inv[i] = pow(fac[i], mod-2, mod) def cmb(n,r): return fac[n] * inv[r] * inv[n-r] % mod for x in range(b,w): c = x + (h - a - 1) d = (w - 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...
s830933891
p04046
Accepted
H,W,A,B = map(int, input().split()) def cmb(n, r, mod): if ( r<0 or r>n ): return 0 r = min(r, n-r) return g1[n] * g2[r] * g2[n-r] % mod mod = 10**9+7 #出力の制限 n = 3*10**5 g1 = [1, 1] # 元テーブル g2 = [1, 1] #逆元テーブル inverse = [0, 1] #逆元テーブル計算用テーブル for i in range( 2, n + 1 ): g1.append( ( g1[-1] * i...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s549542919
p04046
Accepted
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda :sys.stdin.readline().rstrip() class modfact(object): def __init__(self,n): fact=[1]*(n+1) invfact=[1]*(n+1) for i in range(1,n+1): fact[i]=i*fact[i-1]%MOD invfact[n]=pow(fact[n],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...
s856396621
p04046
Accepted
U = 2*10**6 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 z = fact[n] z *= fact_inv[k] z %= MOD 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...
s917517570
p04046
Accepted
mod = 10**9 + 7 h, w, a, b = list(map(int, input().split())) t_mod = [1] * (h+w-1) for i in range(1, h+w-1): t_mod[i] = i * t_mod[i-1] % mod t_modinv = list(map(lambda v: pow(v, mod-2, mod), t_mod)) def comb(n, r): return t_mod[n] * t_modinv[r] * t_modinv[n-r] % mod ans = comb(h-a-1+b, b) * comb(a+w-1-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...
s447264201
p04046
Accepted
import sys input = sys.stdin.readline #str 注意 class Combination: def __init__(self, n_max, mod=10**9+7): self.mod = mod self.modinv = self.make_modinv_list(n_max) self.fac, self.facinv = self.make_factorial_list(n_max) def __call__(self, n, r): return self.fac[n] * self.facinv[...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s762101216
p04046
Accepted
#cmb mod=10**9+7 MAX=2*10**5+100 g1=[1,1] g2=[1,1] for i in range(2,MAX+1): num_1=g1[-1]*i%mod g1.append(num_1) g2.append(pow(num_1,mod-2,mod)) def cmb(n,r,MOD): return g1[n]*g2[r]*g2[n-r]%MOD h,w,a,b=map(int,input().split()) ans=0 for i in range(1,h-a+1): ans=(ans+cmb(i+b-2,i-1,mod)*cmb(h-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...
s345625476
p04046
Accepted
def main(): H, W, A, B = map(int, input().split()) mod = 10**9 + 7 ans = 0 # 予め階乗を計算しておく f = [1] for i in range(H+W): f.append(f[i]*(i+1)%mod) # 組み合わせ関数 def comb_mod(n, r, p): return f[n] * pow(f[r], p-2, p) * pow(f[n-r], p-2, p) for i in range(H-A): 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...
s978992479
p04046
Accepted
MOD = 10 ** 9 + 7 fac = [1] * 200005 for i in range(len(fac) - 1): fac[i + 1] = fac[i] * (i + 1) % MOD h, w, a, b = map(int, input().split()) ans = 0 x, y = b, h - a - 1 while x < w and y >= 0: p = w - x - 1 q = h - y - 1 ans += (fac[x + y] * pow(fac[x] * fac[y], MOD - 2, MOD) * fac[p + q] *...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s908740655
p04046
Accepted
n=200000 mod=10**9+7 def pf(x,y,p): if y==0: return 1 if y%2==0: d=pf(x,y//2,p) return d*d%p if y%2==1: return (x*pf(x,y-1,p))%p facl=[1] for i in range(1,n+2): facl.append(facl[i-1]*i%mod) invl=[1]*(n+2) for i in range(1,n+2): invl[i]=pf(facl[i],mod-2,mod) def comb(x,k): if x<0 or k<0 or x<k: 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...
s914440244
p04046
Accepted
H,W,A,B = map(int, input().split()) MOD = 10 ** 9 + 7 N = H+W+1 def power(base, num): if num == 0: return 1 elif num % 2==0: return power(base, num//2) **2 % MOD elif num==1: return base % MOD else: return power(base, num//2) **2 * base % MOD fact = [0 for i in range(N...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s795050232
p04046
Accepted
def examD(mod): class combination(): def __init__(self, n, mod): self.n = n self.fac = [1] * (n + 1) self.inv = [1] * (n + 1) for j in range(1, n + 1): self.fac[j] = self.fac[j - 1] * j % mod self.inv[n] = pow(self.fac[n], 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...
s336683200
p04046
Accepted
h,w,a,b = map(int, input().split()) mod = 10**9+7 #出力の制限 N = h+w g1 = [1, 1] # 元テーブル g2 = [1, 1] #逆元テーブル inverse = [0, 1] #逆元テーブル計算用テーブル 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...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s327530695
p04046
Accepted
# python3 (3.4.3) import sys input = sys.stdin.readline # functions 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...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s382439573
p04046
Accepted
import sys sys.setrecursionlimit(10 ** 9) def extgcd(a, b): x, y = 0, 0 def f(a, b): nonlocal x, y if b == 0: x = 1 y = 0 return a g = f(b, a % b) q = a // b next_x = y y = x - q * y x = next_x return g ...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s994420657
p04046
Accepted
import math H, W, A, B = map(int,input().split()) e = 10**9 + 7 def power(a,b): if b == 0: return 1 elif b == 1: return a % e elif b%2 == 0: return power(a,b//2)**2 % e else: return power(a,b//2)**2*a % e M = [1] for i in range(1,H+W): a = M[i-1]*i%e M.append...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s123113390
p04046
Accepted
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math import bisect import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, floor, at...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s249391061
p04046
Accepted
h, w, a, b = map(int, input().split()) mod = 1000000007 def modpow(x, y): if y == 0 : return 1 elif y == 1 : return x % mod elif y % 2 == 0 : return modpow(x, y//2)**2 % mod else : return modpow(x, y//2)**2 * x % mod stairs = [1] for i in range(1, h+w+1): stairs.append(stai...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s047016651
p04046
Accepted
# D イロハちゃんと升目 cnt=0 h,w,a,b=map(int,input().split()) def find_power(n): # 0!からn!までのびっくりを出してくれる関数 powlist=[0]*(n+1) powlist[0]=1 powlist[1]=1 for i in range(2,n+1): powlist[i]=powlist[i-1]*i%(10**9+7) return powlist def find_inv_power(n): #0!からn!までの逆元を10**9+7で割ったあまりリストを作る関数 powli...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s965593467
p04046
Accepted
MOD = 1000000007 def mod_pow(a, n, mod): """ 二分累乗法による a^n (mod m)の実装 :param a: 累乗の底 :param n: 累乗の指数 :param mod: 法 :return: a^n (mod m) """ result = 1 a_n = a while n > 0: if n & 1: result = result * a_n % mod a_n = a_n * a_n % mod n >>= 1 ...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s485537487
p04046
Accepted
H, W, A, B = map(int, input().split()) MOD = 10 ** 9 + 7 limit = 2 * 10 ** 5 # modしながらコンビネーションを求める def mod_cmb(n, r, mod): x = fact[n] * fact_inverse[r] % mod x = x * fact_inverse[n - r] % mod return x def d_cmb(n, r, mod): return mod_cmb(n + r - 1, r, mod) # modしたa^bを求める def mod_pow(a, p, 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...
s821772417
p04046
Accepted
def modpow(a, n, mod): res = 1 while n > 0: if (n & 1): res = res * a % mod a = a * a % mod n >>= 1 return res DIV = 10**9 + 7 h, w, a, b = map(int, input().split()) ans = 0 #最大h+w!までの元と逆元の階乗テーブルを求めておく #逆元をFermatの小定理により計算 #p-2乗は二分累乗法にて高速に計算可能 table = [1 for i in range(h + w + 1)] inv_table = [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...
s913098540
p04046
Accepted
import operator as op from functools import reduce MOD = (10 ** 9) + 7 factors = [1, 1] finv = [1, 1] inv = [0, 1] for i in range(2, 200010): factors.append(factors[i - 1] * i % MOD) inv.append(MOD - inv[MOD % i] * (MOD // i) % MOD) finv.append(finv[i - 1] * inv[i] % MOD) def nck(n, k): if n < k or ...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s108657469
p04046
Accepted
def cmb(n, r, mod): if ( r<0 or r>n ): return 0 else: r = min(r, n-r) return g1[n] * g2[r] * g2[n-r] % mod mod = 10**9+7 #出力の制限 N = 200000 g1 = [1, 1] # 元テーブル g2 = [1, 1] #逆元テーブル inverse = [0, 1] #逆元テーブル計算用テーブル for i in range( 2, N + 1 ): g1.append( ( g1[-1] * i ) % 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...
s709531209
p04046
Accepted
MOD = 10**9 + 7 factorials = [1] for i in range(1, 200000): factorials.append((factorials[-1] * i) % MOD) invs = [pow(x, MOD - 2, MOD) for x in factorials] def combinations(n, k): return (factorials[n] * invs[k] * invs[n - k]) % MOD def f(x, y): return combinations(x + y - 2, x - 1) h, w, a, b = map(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...
s840178363
p04046
Accepted
def cmb(n, r, mod): if ( r<0 or r>n ): return 0 r = min(r, n-r) return g1[n] * g2[r] * g2[n-r] % mod mod = 10**9+7 #出力の制限 N = 10**5*2 g1 = [1, 1] # 元テーブル g2 = [1, 1] #逆元テーブル inverse = [0, 1] #逆元テーブル計算用テーブル for i in range( 2, N + 1 ): g1.append( ( g1[-1] * i ) % mod ) inverse.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...
s646453543
p04046
Accepted
def main(): h,w,a,b=map(int,input().split(' ')) mod = 10**9+7 mx=max(h,w) fac=[1]*(h+w+1) for i in range(1,h+w+1): fac[i]=fac[i-1]*i%mod rev=[1]*(mx+1) rev[-1]=pow(fac[mx],mod-2,mod) for i in range(mx-1,-1,-1): rev[i]=rev[i+1]*(i+1)%mod const=rev[h-a-1]*rev[a-1]%mod ...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s666463650
p04046
Accepted
h, w, a, b = map(int, input().split()) mod = 10 ** 9 + 7 ans = 0 for i in range(1, h-a+1): if i == 1: t1 = 1 t2 = 1 for j in range(1, ((h-a-i)+(b-1)+1)): t1 *= j t1 %= mod for j in range(1, ((b-1)+1)): t2 *= j t2 %= mod for j 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...
s127508062
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[i-1]*i) % MOD) INV.append(pow(FAC[-1],MOD-2,MOD)) #print(FAC) #print(INV) def nCr(n,r): return FAC[n]*INV[n-r]*INV[r] ans = 0 for i in range(H-A): ans += nCr(i+B-1,min(i,B-1)) * nCr(H-i-1+W-B-1,min(...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s999920794
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...
s414286945
p04046
Accepted
h, w, a, b = map(int, input().split()) res = 0 kai = min(w - b, h - a) mod = 10 ** 9 + 7 kaijo = [0] * (h + w + 1) kaijo[0] = 1 for i in range(1, h + w + 1): kaijo[i] = (kaijo[i - 1] * i) % mod gyaku = [0] * (h + w + 1) gyaku[h + w] = pow(kaijo[h + w], mod - 2, mod) for i in range(h + w, 0, -1): gyaku[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...
s599301426
p04046
Accepted
class ModComb: def __init__(self, MAX, mod=10 ** 9 + 7): fac = [1, 1] finv = [1, 1] inv = [0, 1] for i in range(2, MAX): fac.append(fac[i - 1] * i % mod) inv.append(mod - inv[mod % i] * (mod // i) % mod) finv.append(finv[i - 1] * inv[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...
s197408261
p04046
Accepted
import sys import heapq import bisect mod = 10**9+7 dd = ((-1,0),(1,0),(0,-1),(0,1)) def I(): return(int(sys.stdin.readline())) def LI(): return([int(x) for x in sys.stdin.readline().split()]) def S(): return(sys.stdin.readline()[:-1]) def IR(n): return([I() for _ in range(n)]) def GCD(a,b): while 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...
s794919852
p04046
Accepted
def d_iroha_and_a_grid(MOD=10**9 + 7): class Combination(object): """参考: https://harigami.net/contents?id=5f169f85-5707-4137-87a5-f0068749d9bb""" __slots__ = ["mod", "factorial", "inverse"] def __init__(self, max_n: int = 10**6, mod: int = 10**9 + 7): fac, inv = [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...
s089927811
p04046
Accepted
H, W, A, B = map(int,input().split()) MOD = 10**9 + 7 fac = [1 for k in range(200010)] inv = [1 for k in range(200010)] finv = [1 for k in range(200010)] for k in range(2,200010): fac[k] = (fac[k-1]*k)%MOD inv[k] = (MOD - inv[MOD%k] * (MOD // k))%MOD finv[k] = (finv[k - 1] * inv[k]) % MOD; def nCr(n,r): ...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s704738394
p04046
Accepted
h,w,a,b =map(int,input().split()) mod = 10**9+7 #階乗を求める fact_l = [1 for i in range(h+w+1)] for i in range(1,len(fact_l)): fact_l[i] *= (fact_l[i-1]*i)%mod #逆元 factinv_l = [1 for i in range(h+w+1)] for i in range(1,len(fact_l)): factinv_l[i] = pow(fact_l[i],mod-2,mod) #必ず通るポイントまでの組み合わせ point1 = [1 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...
s941053670
p04046
Accepted
# -*- coding: utf-8 -*- """ Created on Mon Sep 23 17:33:45 2019 ABC042D @author: maezawa """ MAX = 5*10**5+1 MOD = 10**9+7 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...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s912710788
p04046
Accepted
inp=input().split(" ") H=int(inp[0]) W=int(inp[1]) A=int(inp[2]) B=int(inp[3]) mod=10**9+7 fact=[1] fact_r=[1] for i in range(1,H+W-1): fact.append(i*fact[i-1]%mod) fact_r.append(pow(fact[i],10**9+5,mod)) const=fact_r[H-A-1]*fact_r[A-1]%mod ans=sum(fact[H+i-A-1]*fact_r[i]*fact_r[W-i-1]*fact[W-i-2+A]%mod 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...
s288113799
p04046
Accepted
h, w, a, b = map(int,input().split()) mod = 10**9 + 7 def inv(x, p): pp = p-2 ans = 1 while pp > 0: if pp % 2 == 1: ans = (ans * x) % p x = (x ** 2) % p pp //= 2 return ans I = [1] + [inv(i, mod) for i in range(1, h+w+1)] a0 = 1 a1 = 1 for i in range(w-b+a-1, (w-b+...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s279715662
p04046
Accepted
h, w, a, b = map(int, input().split()) m = h + w mod = 10 ** 9 + 7 fac = [1] * (m + 1) inv = [1] * (m + 1) for i in range(1, m + 1): fac[i] = fac[i - 1] * i % mod inv[-1] = pow(fac[-1], mod - 2, mod) for i in range(m - 1, -1, -1): inv[i] = inv[i + 1] * (i + 1) % mod def cmb(n, r): assert n >= 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...
s362412979
p04046
Accepted
h, w, a, b = map(int, input().split()) m = h + w mod = 10 ** 9 + 7 fac = [1] * (m + 1) inv = [1] * (m + 1) for i in range(1, m + 1): fac[i] = fac[i - 1] * i % mod inv[-1] = pow(fac[-1], mod - 2, mod) for i in range(m - 1, -1, -1): inv[i] = inv[i + 1] * (i + 1) % mod def cmb(n, r): assert n >= 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...
s719264998
p04046
Accepted
def solve(): h,w,a,b = map(int, input().split()) mx = max(h,w) mod = 10**9+7 fac = [1]*(h+w+1) for i in range(1,h+w+1): fac[i]=fac[i-1]*i%mod inv = [1]*(mx+1) inv[-1] = pow(fac[mx], mod-2, mod) for i in range(mx-1, -1, -1): inv[i] = inv[i+1]*(i+1)%mod const = inv[h-a-1]*inv[a-1]%mod ans = sum(fac[h-a+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...
s916785866
p04046
Accepted
def solve(): h,w,a,b = map(int, input().split()) mx = max(h,w) mod = 10**9+7 fac = [1]*(h+w+1) for i in range(1,h+w+1): fac[i]=fac[i-1]*i%mod rev = [1]*(mx+1) rev[-1] = pow(fac[mx], mod-2, mod) for i in range(mx-1, -1, -1): rev[i] = rev[i+1]*(i+1)%mod const = rev[h-a-1]*rev[a-1]%mod ans = sum(fac[h-a+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...
s036969789
p04046
Accepted
h, w, a, b = map(int, input().split(" ")) div = 10 ** 9 + 7 size = h + w - 1 fact = [0] * size inverse = [0] * size inv_calced = [0] * size fact[:2] = [1, 1] inverse[:2] = [1, 1] inv_calced[:2] = [0, 1] for i in range(2, size): fact[i] = fact[i - 1] * i % div inv_calced[i] = -inv_calced[div % i] * (div // i) % di...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s184490188
p04046
Accepted
from math import factorial 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 = [pow(fact[-1], MOD-2, MOD)] # x^(-1) = x^(10^9+5) % (10^9+7), フェルマーの小定理 for i in range(h+w-2, 0, -1): # xが最大の場合を求め、後ろ向きに計算していく 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...
s888043059
p04046
Accepted
def cmb(n,r,mod): if r<0 or r>n: return 0 r=min(r,n-r) return g1[n]*g2[r]*g2[n-r]%mod h,w,a,b=map(int,input().split()) m=10**9+7 g1=[1,1] g2=[1,1] inverse=[0,1] for i in range(2,h+w): g1.append((g1[-1]*i)%m) inverse.append((-inverse[m%i]*(m//i))%m) g2.append((g2[-1]*inverse[-1])%m) ans=0 for i in...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s389569360
p04046
Accepted
import sys input=sys.stdin.readline mod = 10**9+7 def nCr(fact, inv, n, r): return fact[n] * inv[r] * inv[n-r] % mod def main(): H,W,A,B = map(int,input().split()) fact = [1] for i in range(1, H+W+1): fact.append(fact[i-1] * i % mod) inv = [0] * (H+W+1) inv[H+W] = pow(fact[H+W], 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...
s474408345
p04046
Accepted
H, W, A, B = map(int, input().split()) MOD = 10 ** 9 + 7 def pow_mod(x, p): res = 1 while p: if p % 2: res = res * x % MOD x = x * x % MOD p //= 2 return res F = [1] invF = [] def comb_mod(n, r): return F[n] * invF[r] * invF[n - r] % MOD for i in range(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...
s535075235
p04046
Accepted
h, w, a, b = map(int, input().split()) MOD = 10**9 + 7 MAX = h+w + 5 fact = [1 for _ in range(MAX)] finv = [1 for _ in range(MAX)] for i in range(2, MAX): fact[i] = fact[i - 1] * i % MOD finv[i] = pow(fact[i], MOD-2, MOD) def comb(n: int, k: int) -> int: if n < k or n < 0 or k < 0: return 0 re...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s912252153
p04046
Accepted
h,w,a,b = map(int,input().split()) n = h+w mod = 10**9+7 fun = [1]*(n+1) for i in range(1,n+1): fun[i] = fun[i-1]*i%mod rev = [1]*(n+1) rev[n] = pow(fun[n],mod-2,mod) for i in range(n-1,0,-1): rev[i] = rev[i+1]*(i+1)%mod def nCr(n,r): if r > n: return 0 return fun[n]*rev[r]%mod*rev[n-r]%mod 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...
s570825384
p04046
Accepted
H, W, A, B = map(int, input().split()) def cmb(n, r, mod): if (r < 0 or r > n): return 0 r = min(r, n-r) # print(n, r) return g1[n] * g2[r] * g2[n-r] % mod mod = 10**9+7 # 出力の制限 N = 10**5*2 g1 = [1, 1] # 元テーブル g2 = [1, 1] # 逆元テーブル inverse = [0, 1] # 逆元テーブル計算用テーブル for i in range(2, N + 1...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s627910676
p04046
Accepted
H, W, A, B = [int(_) for _ in input().split()] p = 10 ** 9 + 7 # 二分累乗法 で n^x % p を求める # pow(n,x,p) で得られるので次からはそっちつかう def power(n, x, p): return pow(n,x,p) # a = n # a^(2^0), a^(2^1), ... # ans = 1 # while x > 0: # if x & 1: # ans = (ans * a) % p # x = x >> 1 # a = ...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s027459614
p04046
Accepted
h,w,a,b = map(int,input().split()) n = h+w mod = 10**9+7 fun = [1]*(n+1) for i in range(1,n+1): fun[i] = fun[i-1]*i%mod rev = [1]*(n+1) rev[n] = pow(fun[n],mod-2,mod) for i in range(n-1,0,-1): rev[i] = rev[i+1]*(i+1)%mod def nCr(n,r): if r > n: return 0 return fun[n]*rev[r]%mod*rev[n-r]%mod 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...
s072918915
p04046
Accepted
h,w,a,b=map(int,input().split()) n=h+w MOD = 10**9+7 def inv_mod(a, p=MOD): def inv_mod_sub(a, p): if a == 1: return 1, 0 else: d, r = p//a, p%a x, y = inv_mod_sub(r, a) return y-d*x, x if p < 0: p = -p a %= p return inv_mod_sub(a,p)[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...
s855431798
p04046
Accepted
H,W,A,B = map(int,input().split()) mod = 10**9 + 7 f = [1] for i in range(H+W): f.append(f[i]*(i+1)%mod) def comb(A,B,mod): return f[A] * pow(f[B],mod-2,mod) * pow(f[A-B],mod-2,mod) % mod res = 0 for i in range(B,W): res += comb(H-A+i-1,i,mod) * comb(A+W-i-2,A-1,mod) % mod 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...
s634995909
p04046
Accepted
H, W, A, B = map(int, input().split()) ans = 0 def cmb(n, r, mod): if ( r<0 or r>n ): return 0 r = min(r, n-r) return g1[n] * g2[r] * g2[n-r] % mod mod = 10**9+7 #出力の制限 N = maximum = max(H - A + W - 2, W + A - B - 2) g1 = [1, 1] # 元テーブル g2 = [1, 1] #逆元テーブル inverse = [0, 1] #逆元テーブル計算用テーブル for i in...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s392990076
p04046
Accepted
def main(): H, W, A, B = map(int, input().split()) mod = pow(10, 9) + 7 v = 1 fs = [v] for i in range(1, H+W-1): v = (v * i) % mod fs.append(v) v = invfactorial(H+W-2, mod) invfs = [v] for i in range(H+W-2, 0, -1): v = (v * i) % mod invfs.append(v) ...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s978275619
p04046
Accepted
import sys input = sys.stdin.readline def main(): H, W, A, B = map(int, input().split()) MOD = int(1e9) + 7 kai = [1] * (max(H-A+W, A+W-B) + 1) for i in range(1, len(kai)): kai[i] = kai[i-1] * i kai[i] %= MOD up = [0] * (W-B) down = [0] * (W-B) t1 = H-A-1 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...
s467223421
p04046
Accepted
h,w,a,b=map(int,input().split()) mod=10**9+7 f=[1] for i in range(h+w): f.append(f[i]*(i+1)%mod) def comb(a,b,mod): return f[a] * pow(f[b], mod-2, mod) * pow(f[a-b], mod-2, mod) % mod ans=0 for i in range(b,w): ans+= comb(h-a+i-1, i, mod) * comb(a+w-i-2, a-1, mod) % 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...
s625631003
p04046
Accepted
H,W,A,B = map(int,input().split()) 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 : ...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s120761855
p04046
Accepted
H, W, A, B = map(int, input().split()) def cmb(n, r, mod): if ( r<0 or r>n ): return 0 r = min(r, n-r) return g1[n] * g2[r] * g2[n-r] % mod mod = int(10**9+7) #出力の制限 NN = 10**6 # 使うデータによって変える g1 = [1, 1] # 元テーブル g2 = [1, 1] #逆元テーブル inverse = [0, 1] #逆元テーブル計算用テーブル for i in range( 2, NN + 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...
s663401109
p04046
Accepted
H,W,A,B = map(int, input().split()) N = H+W MOD = 10**9 + 7 def mul(a, b): return ((a % MOD) * (b % MOD)) % 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 def...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s166950783
p04046
Accepted
from operator import mul from functools import reduce from functools import lru_cache H,W,A,B = map(int,input().split()) ans = 0 mod = 10**9+7 lru_cache(maxsize=None) def cmb(c, r): return fc[c + r] * ic[c] * ic[r] % mod fc = [1] * (H + W) for i in range(2, H+W): fc[i] = fc[i - 1] * i % mod ic = [pow(x, 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...
s405670711
p04046
Accepted
h,w,a,b=map(int,input().split()) 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] ...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s180214633
p04046
Accepted
H, W, A, B = map(int, input().split()) MOD = 10 ** 9 + 7 def get_fact_list(n: int) -> list: result_list = [1] tmp = 1 for i in range(n): tmp = (tmp * (i + 1)) % MOD result_list.append(tmp) return result_list def get_inv_list(n: int, fact_lit: list) -> list: result_list = [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...
s372949913
p04046
Accepted
# ARC058D - いろはちゃんとマス目 / Iroha and a Grid (ABC042D) def get_fact(lim): # compute a toble of factorials (1-idx) fact = [1] * (lim + 1) x = 1 for i in range(1, lim + 1): x = (x * i) % MOD fact[i] = x return fact def get_inv(lim): # compute a toble of inverse factorials (1-idx) ...
2 3 1 1
2
<span class="lang-en"> <p>Score : <var>400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the b...
s205926498
p04046
Accepted
# ABC042D - いろはちゃんとマス目 / Iroha and a Grid (ARC058D) def comb(n: int, r: int) -> int: return fact[n] * inv[n - r] * inv[r] def main(): global fact, inv H, W, A, B = tuple(map(int, input().split())) MOD = 10 ** 9 + 7 # table of factorials fact, x = [1] * (H + W + 1), 1 for i in range(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...