submission_id string | problem_id string | status string | code string | input string | output string | problem_description string |
|---|---|---|---|---|---|---|
s746656996 | p04046 | Accepted | from math import factorial
mod = 10**9 + 7
H, W, A, B = map(int, input().split())
memo_fact = [1] * (H + W - 1)
memo_denometer = {}
for i in range(1, H + W - 1):
memo_fact[i] = memo_fact[i - 1] * i % mod
def nCr(n,r):
numerator = memo_fact[n]
if (n, r) in memo_denometer:
denometer = memo_denometer[(n, r)]
else:
denometer = pow(memo_fact[r], mod-2, mod) * pow(memo_fact[n-r], mod-2, mod)
return (numerator * denometer) % mod
result = 0
for i in range(1, H - A + 1):
result += (nCr((B-1)+(i-1), i-1) * nCr((W-B-1)+(H-i), W-B-1)) % mod
print(int(result % 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 bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s679606905 | p04046 | Accepted | H, W, A, B = map(int,input().split())
P = 10**9+7
# H, W, A, B = map(int,"2 3 1 1".split())
M = H+W-1
factlist = [1] * (H+W)
factinvlist = [1] * (H+W)
t = 1
for i in range(M):
t = (t * (i+1)) % P
factlist[i+1] = t
t = pow(factlist[M],P-2,P)
factinvlist[M] = t
for i in range(M):
t = (t * (M-i)) % P
factinvlist[M-i-1] = t
def comb(i,j):
return (factlist[i+j] * factinvlist[i] * factinvlist[j]) % P
s = 0
i = 0
while H-A-i-1 >= 0 and B+i <= W and A+i <= H and W-B-i-1 >= 0:
# print((H-A-i,B+i+1))
s = (s + comb(H-A-i-1,B+i) * comb(A+i,W-B-i-1)) % P
i += 1
print(s)
| 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s128137736 | p04046 | Accepted | import math
H, W, A, B = map(int, input().split())
p = 10 ** 9 + 7
F = [1 for i in range(H + W + 1)]
for i in range(1, H + W + 1):
F[i] = F[i - 1] * i % p
def fac(a, b):
a = F[a + b] * pow(F[a], p - 2, p) * pow(F[b], p - 2, p)
return a % p
ans = 0
for h in range(H - A):
ans += fac(h, B - 1) * fac(H - h - 1, W - B - 1) % p
print(ans % p) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s194883361 | p04046 | Accepted | import math
H, W, A, B = map(int, input().split())
p = 10 ** 9 + 7
F = [1 for i in range(H + W + 1)]
for i in range(1, H + W + 1):
F[i] = F[i - 1] * i % p
def fac(a, b):
a = F[a + b] * pow(F[a], p - 2, p) * pow(F[b], p - 2, p)
return a % p
if H - A < B:
ans = 0
for h in range(H - A):
ans += fac(h, B - 1) * fac(H - h - 1, W - B - 1) % p
else:
ans = fac(H - 1, W- 1)
for w in range(B):
ans -= fac(H - A - 1, w) * fac(A - 1, W - w - 1) % p
print(ans % p) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s635896283 | p04046 | Accepted | h, w, a, b = [int(i) for i in input().split()]
p = 10 ** 9 + 7
ans = 0
c = h-a-1
def fact(n, p=10**9 + 7):
f = [1]
for i in range(1, n+1):
f.append(f[-1]*i%p)
return f
def invfact(n, f, p=10**9 + 7):
inv = [pow(f[n], p-2, p)]
for i in range(n, 0, -1):
inv.append(inv[-1]*i%p)
return inv[::-1]
f = fact(h+w-2)
invf = invfact(h+w-2, f)
def comb(a, b):
return f[a] * invf[b] * invf[a-b] % p
for x in range(b, w):
ans = (ans + (comb(c+x, min(x, c)) * comb(a-1+w-x-1, min(a-1, w-x-1)) % p)) % p
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 bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s544387429 | p04046 | Accepted | h,w,a,b=map(int,input().split())
mod=10**9+7
fuc=[1]
for i in range(1,h+w):
e=fuc[i-1]*i
fuc.append(e%mod)
def com(n,k):
com=(fuc[n]%mod)*pow(fuc[k],mod-2,mod)*pow(fuc[n-k],mod-2,mod)
return com
s=0
for i in range(1,h-a+1):
s+=com(i-2+b,i-1)*com(w-b-1+h-i,w-b-1)
print(s%mod) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s283802692 | p04046 | Accepted | MOD = 10**9+7
h, w, a, b = list(map(int, input().split()))
ans = 0
facts = [1]
for i in range(1, h+w-1):
facts.append((i*facts[i-1])%MOD)
# print(facts[:20])
def get_path(n, r):
return (facts[n] * pow(facts[r], MOD-2, MOD)%MOD * pow(facts[n-r], MOD-2, MOD)%MOD) % MOD
y, x = h-a, b+1
while(True):
path_0 = get_path(y+x-2, x-1)
path_1 = get_path(h-y+w-x, w-x)
# print(y, x, path_0, path_1)
ans += (path_0*path_1)%MOD
ans %= MOD
y -= 1
x += 1
if y == 0 or x > w:
break
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 bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s585290602 | p04046 | Accepted | h, w, a, b = map(int, raw_input().split())
mod = 1000000007
inv = [0] * (h+w)
fact = [0] * (h+w)
def ex(x, y):
if y == 0: return 1
elif y == 1: return x % mod
elif y % 2 == 0: return ex(x, y/2) ** 2 % mod
else: return ex(x, y/2) ** 2 * x % mod
# factorial
fact[0]=1
for j in range(1, h+w):
fact[j] = fact[j-1] * j % mod
inv[h+w-1]=ex(fact[h+w-1],mod-2)
for j in reversed(range(h+w-1)):
inv[j]=inv[j+1]*(j+1)%mod
def nck(x, y):
return fact[x] * inv[y] * inv[x-y] % mod
su = 0
for j in range(h-a):
su = (su+nck(b-1+j, b-1)*nck(h-1-j+w-1-b, w-1-b)) % mod
print(su)
| 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s847931817 | p04046 | Accepted | H, W, A, B = (int(i) for i in input().split())
#H, W, A, B = (10, 7, 3, 4)
#H, W, A, B = (2, 3, 1, 1)
def mycomb(n,r):
return (factorials[n] * pow(factorials[r],MOD-2,MOD) % MOD) * pow(factorials[n-r],MOD-2,MOD) % MOD
MOD = int(1e9 + 7)
factorials = []
factorials.append(1)
for i in range(1, W + H):
factorials.append((factorials[i - 1] * i) % MOD)
r = 0
for i in range(H - A):
combination = mycomb(B-1+i, B-1) * mycomb(W+H-B-i-2, W-B-1)
r += int(combination)
print(r%MOD)
| 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s096040657 | p04046 | Accepted | # 拡張ユークリッド互除法
# ax + by = gcd(a,b)の最小整数解を返す
def egcd(a, b):
if a == 0:
return b, 0, 1
else:
g, y, x = egcd(b % a, a)
return g, x - (b // a) * y, y
# mを法とするaの乗法的逆元
def modinv(a, m):
g, x, y = egcd(a, m)
if g != 1:
raise Exception('modular inverse does not exist')
else:
return x % m
# nCrをすべてのr(0<=r<=n)について求める
def combination(n, mod):
lst = [1]
for i in range(1, n+1):
lst.append(lst[-1] * (n+1-i) % mod * modinv(i, mod) % mod)
return lst
H, W, A, B = map(int, input().split())
x, y = B, H-A-1
n1 = x+y
n2 = W+H-n1-2
mod = 10**9+7
C1 = combination(n1, mod)
C2 = combination(n2, mod)
ans = 0
while x<W and y>=0:
ans += C1[x] * C2[W-x-1]
ans %= mod
x += 1
y -= 1
print(ans)
| 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s309254301 | p04046 | Accepted | def ext_gcd(a,b):
"""returns tuple (gcd(a,b), x, y) s.t. ax+by=gcd(a,b)"""
if b==0:
return (a,1,0)
g,x,y = ext_gcd(b,a%b)
return (g,y,x-a//b*y)
def invmod_by_gcd(a,P):
_,x,y = ext_gcd(a,P)
return (x+P) % P
F = []
FInv = []
def init_factorials(L,P):
"""initialize F and FInv less than L"""
global F, FInv
F = [1 for _ in range(L)]
for i in range(1,L):
F[i] = (F[i-1]*i)%P
FInv = [1 for _ in range(L)]
FInv[L-1] = invmod_by_gcd(F[L-1],P)
for i in range(L-2,0,-1):
FInv[i] = (FInv[i+1]*(i+1))%P
def combination(a, b, P):
return (F[a]*FInv[b]*FInv[a-b])%P
P = 10**9+7
H,W,A,B = map(int,input().split())
init_factorials(H+W,P)
ans = 0
for k in range(H-A):
a = combination(B+k-1,B-1,P)
b = combination(H+W-k-B-2,H-1-k,P)
ans = (ans + a*b%P)%P
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 bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s147965354 | p04046 | Accepted | import sys
sys.setrecursionlimit(10000000)
p = 10**9+7
def power(a,b):
if b == 0:
return 1
elif b%2 == 0:
return (power(a,b//2)**2)%p
else:
return (a*power(a,b//2)**2)%p
def fact(a):
if a <= 0:
return 1
else:
return (a*fact(a-1))%p
H,W,A,B = map(int,input().strip().split(" "))
a,b = fact(H+B-A-1)%p,fact(W+A-B-1)%p
c,d = H-A-1,W-B-1
m = max(H-1,W-1)
mods = [1]*(m+1)
mods[m] = power(fact(m),p-2)
for i in range(m):
mods[m-i-1] = (mods[m-i]*(m-i))%p
ans = 0
for i in range(min(c,d)+1):
ans = (ans+a*b*mods[A+i]*mods[B+i]*mods[c-i]*mods[d-i])%p
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 bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s165369339 | p04046 | Accepted | H,W,A,B = map(int,input().split())
MOD = 10**9+7
fact = [1]*200001
t = 1
for i in range(1,200001):
t = (t*i)%MOD
fact[i] = t
def ncr(n,r):
return (fact[n] * pow(fact[r],MOD-2,MOD) % MOD) * pow(fact[n-r],MOD-2,MOD) % MOD
Ans = 0
for i in range(H-A):
Ans += ncr(i+B-1,i)*ncr(W-B+H-i-2,W-B-1)
print(Ans%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 bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s292088103 | p04046 | Accepted | MOD = 10**9+7
N = 200000
p = [1] * (N+1)
q = [1] * (N+1)
for i in range(1, N+1):
p[i] = (p[i-1]*(i)%MOD)
q[0] = pow(p[-1], MOD-2, MOD)
for i in range(1, N+1):
q[i] = (N-i+1)*q[i-1]%MOD
q.reverse()
def nCk(n,k):
if k > n or (k != 0 and n == 0):
return 0
elif k == 0:
return 1
else:
return p[n]*q[k]%MOD*q[n-k]%MOD
h,w,a,b = map(int, input().split())
ans = 0
for i in range(b, w):
ans += nCk(h-a+i-1, i)*nCk(w-i-2+a, 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 bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s064986065 | p04046 | Accepted | MOD = 10**9+7
N = 200000
p = [1] * (N+1)
q = [1] * (N+1)
for i in range(1, N+1):
p[i] = (p[i-1]*(i)%MOD)
q[0] = pow(p[-1], MOD-2, MOD)
for i in range(1, N+1):
q[i] = (N-i+1)*q[i-1]%MOD
q.reverse()
def nCk(n,k):
if k > n or n == 0:
return 0
elif k == 0:
return 1
else:
return p[n]*q[k]%MOD*q[n-k]%MOD
h,w,a,b = map(int, input().split())
ans = 0
for i in range(b, w):
ans += nCk(h-a+i-1, i)*nCk(max(1, w-i-2+a), 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 bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s769283594 | p04046 | Accepted | h,w,a,b = (int(i) for i in input().split())
mod,n,ans = 10**9+7,h+w-2,0
fn,fk = [1]*n,[1]*n
for i in range(n-1): fn[i+1] = (fn[i]*(i+2))%mod
def power(n,k):
if k==1: return n
elif k%2==0: return power((n**2)%mod,k//2)
else: return (n*power(n,k-1))%mod
def comb(n,k):
if n==0 or k==0 or n==k: return 1
else: return (((fn[n-1]*fk[n-k-1])%mod)*fk[k-1])%mod
fk[-1] = power(fn[-1],mod-2)
for i in range(2,n+1): fk[-i] = (fk[-i+1]*(n+2-i))%mod
for i in range(h-a): ans = (ans+comb(h+w-b-i-2,h-i-1)*comb(b+i-1,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 bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s464876866 | p04046 | Accepted | H, W, A, B = map(int, input().split())
mod = 10**9 + 7
# 階乗 & 逆元計算
factorial = [1]
inverse = [1]
for i in range(1, 2*10**5):
factorial.append(factorial[-1] * i % mod)
inverse.append(pow(factorial[-1], mod-2, mod))
# 組み合わせ計算
def nCr(n, r):
if n < r or n == 0 or r == 0:
return 1
return factorial[n] * inverse[r] * inverse[n - r] % mod
check_point = []
for i in range(W-B):
check_point.append(nCr(H-A-1+B+i, B+i))
ans = 0
for i in range(W-B):
ans += (nCr(A-1+W-B-i-1, W-B-i-1) * check_point[i]) % 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 bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s327541177 | p04046 | Accepted | import scipy.misc as scm
h, w, a, b = [int(i) for i in input().split()]
p = 10**9 + 7
ans = 0
def fact(n, p=10**9 + 7):
f = [1]
for i in range(1, n+1):
f.append(f[-1]*i%p)
return f
def invfact(n, f, p=10**9 + 7):
inv = [pow(f[n], p-2, p)]
for i in range(n, 0, -1):
inv.append(inv[-1]*i%p)
return inv[::-1]
f = fact(h+w)
rf = invfact(h+w, f)
for i in range(b, w):
ans += (f[h-a+i-1] * rf[h-a-1] % p * rf[i] % p) * (f[a+w-i-2] * rf[a-1] % p * rf[w-i-1] % p) % p
ans %= p
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 bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s109246826 | p04046 | Accepted | import scipy.misc as scm
h, w, a, b = [int(i) for i in input().split()]
p = 10**9 + 7
ans = 0
def fact(n, p=10**9 + 7):
f = [1]
for i in range(1, n+1):
f.append(f[-1]*i%p)
return f
def invfact(n, f, p=10**9 + 7):
inv = [pow(f[n], p-2, p)]
for i in range(n, 0, -1):
inv.append(inv[-1]*i%p)
return inv[::-1]
f = fact(h+w)
rf = invfact(h+w, f)
for i in range(w-b):
wi = b + i
ans += (f[h-a+wi-1] * rf[h-a-1] % p * rf[wi] % p) * (f[a+w-wi-2] * rf[a-1] % p * rf[w-wi-1] % p) % p
ans %= p
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 bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s502101438 | p04046 | Accepted | MOD = 10**9+7
l = list(map(int,input().split()))
h,w,a,b = l[0],l[1],l[2],l[3]
def pow(x,n):
res = 1
while n > 0:
if n % 2 == 1:
res = res*x % MOD
x = x*x % MOD
n = n >> 1
return res
def comb(n,k):
return (fact[n]*inv[k] % MOD)*inv[n-k] % MOD
fact = [1]*1000000
inv = [1]*1000000
for i in range(h+w):
fact[i+1]=fact[i]*(i+1) % MOD
inv[h+w] = pow(fact[h+w],MOD-2) % MOD
for i in range(h+w-1,0,-1):
inv[i] = (i+1)*inv[i+1] % MOD
ans = 0
for i in range(w-b):
ans = (ans + (comb(h-a+b+i-1,b+i)*comb(w-b-i+a-2,a-1) % MOD)) % 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 bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s332148598 | p04046 | Accepted | import itertools
import math
H,W,A,B=map(int,raw_input().split())
mod=10**9+7
FACT={}
n=1
for i in range(H+W-1):
if i==0: n=1
else: n=(n*i)%mod
FACT[i]=n
#print FACT
def C(n,r):
return (FACT[n]*pow(FACT[r],10**9+5 ,mod)*pow(FACT[n-r],10**9+5 ,mod)) %mod
p=0
for i in range(B,W):
p+=C(H-A-1+i,i)*C(A-1+W-i-1,W-i-1)
p=p%mod
print p
| 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s989775515 | p04046 | Accepted | import itertools
import math
H,W,A,B=map(int,raw_input().split())
mod=10**9+7
FACT={}
FACT_INVERSE={}
n=1
for i in range(H+W-1):
if i==0: n=1
else: n=(n*i)%mod
FACT[i]=n
#print FACT
def C(n,r):
return (FACT[n]*pow(FACT[r],10**9+5 ,mod)*pow(FACT[n-r],10**9+5 ,mod)) %mod
p=0
for i in range(B,W):
p+=C(H-A-1+i,i)*C(A-1+W-i-1,W-i-1)
p=p%mod
print p
| 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s257644569 | p04046 | Accepted | M = 10**9 + 7
L = 200000
Fm = {}
inverseFm = {}
x = 1
for i in range(L):
Fm[i] = x
x = x * (i + 1) % M
def inverseFm(x):
result = pow(Fm[x], M - 2, M)
return result
def C(n, r):
result = Fm[n] * inverseFm(r) * inverseFm(n - r) % M
return result
def solve(H, W, A, B):
result = 0
for i in range(B + 1, W + 1):
result += C(i + H - A - 1 - 1, i - 1) * C(W - i + A - 1, W - i)
return result % M
H, W, A, B = [int(_) for _ in input().split()]
print(solve(H, W, A, B))
| 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s788806022 | p04046 | Accepted | M = 10**9 + 7
L = 200000
Fm = {}
inverseFm = {}
x = 1
for i in range(L):
Fm[i] = x
x = x * (i + 1) % M
def inverseFm(x, cache={}):
if x in cache:
return cache[x]
result = pow(Fm[x], M - 2, M)
cache[x] = result
return result
def C(n, r):
result = Fm[n] * inverseFm(r) * inverseFm(n - r) % M
return result
def solve(H, W, A, B):
result = 0
for i in range(B + 1, W + 1):
result += C(i + H - A - 1 - 1, i - 1) * C(W - i + A - 1, W - i)
return result % M
H, W, A, B = [int(_) for _ in input().split()]
print(solve(H, W, A, B))
| 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s743298272 | p04046 | Accepted | H,W,A,B=map(int,input().split())
mod=10**9+7
#繰り返し二乗法
def great_power(x, y):
if y == 0:
return 1
elif y == 1:
return x % mod
elif y % 2 == 0:
return great_power(x, y//2)**2 % mod
else:
return great_power(x, y//2)**2 * x % mod
#階乗計算
factorial=[1]
for i in range(1,H+W):
factorial.append(factorial[i-1]*i %mod)
#逆元計算
inverse=[0]*(H+W)
inverse[H+W-1] = great_power(factorial[H+W-1], mod-2)
for i in range(H+W-2, -1, -1):
inverse[i] = inverse[i+1] * (i+1) % mod
#combination計算
def nCr(n,r):
return factorial[n] * inverse[r] * inverse[n-r] % mod
ans=0
for i in range(B+1,W+1):
ans=(ans+nCr(H-A-1+i-1,i-1) * nCr(A-1+W-i, 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 bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s905446670 | p04046 | Accepted | def d_Iroha_and_a_Grid(H, W, A, B):
# フェルマーの小定理でnCrを定義
n = H + W - 2
M = 10**9 + 7
factrial = [1] * (n + 2)
for k in range(1, n + 2):
factrial[k] = (factrial[k - 1] * k) % M
fact_inv = [1] * (n + 2)
fact_inv[n + 1] = pow(factrial[n + 1], M - 2, M)
for k in range(n, -1, -1):
fact_inv[k] = (fact_inv[k + 1] * (k + 1)) % M
def nCr(n, r, M):
if n < 0 or r < 0 or n < r:
return 0
else:
return (factrial[n] * fact_inv[r] * fact_inv[n - r]) % M
ans = 0
# 左上のマスの座標を(0,0)としたとき、B<=i<=W-1を満たすiについて、
# (0,0)→(H-A-1,i)への行き方 * (H-A-1,i)→(H-A,i)への行き方(1通り) *
# (H-A,i)→(H-1,W-1)への行き方 の値の総和を取る(10**9+7で剰余を取る)
for i in range(B, W):
ans = (ans + nCr(H - A - 1 + i, H - A - 1, M) *
nCr(A - 1 + W - 1 - i, A - 1, M)) % M
return ans
H,W,A,B = [int(i) for i in input().split()]
print(d_Iroha_and_a_Grid(H, W, A, B)) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s869168366 | p04046 | Accepted | mod = 1000000007
facto = [1]*200001
tmp = 1
for i in range(1,200001):
tmp = (tmp*i)%mod
facto[i] = tmp
def ncr(n,r):
return (facto[n] * pow(facto[r],mod-2,mod) % mod) * pow(facto[n-r],mod-2,mod) % mod
h,w,a,b = map(int,input().split())
ret = 0
for i in range(h-a):
ret += ncr(b-1+i,i)*ncr(h-i-1+w-b-1,h-i-1)%mod
print(ret%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 bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s292690386 | p04046 | Accepted | def power_func(a,b,p):
"""a^b mod p を求める"""
if b==0: return 1
if b%2==0:
d=power_func(a,b//2,p)
return d*d %p
if b%2==1:
return (a*power_func(a,b-1,p ))%p
H,W,A,B=map(int, input().split())
p=10**9+7
X=[1] #階乗テーブル
for i in range(1,H+W-1):
X+=[ (X[-1]*i) %p ]
Y=[1]*(H+W-1) #階乗の逆元テーブル
Y[H+W-2]=power_func(X[H+W-2],p-2,p)
for i in range(H+W-3,-1,-1):
Y[i]=Y[i+1]*(i+1) %p
ans=0
for i in range(B,W):
ans+=X[H-A-1+i]*X[A+W-2-i]*Y[H-A-1]*Y[i]*Y[A-1]*Y[W-1-i]
print(ans%p) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s468564545 | p04046 | Accepted | def power_func(a,b,p):
"""a^b mod p を求める"""
if b==0: return 1
if b%2==0:
d=power_func(a,b//2,p)
return d*d %p
if b%2==1:
return (a*power_func(a,b-1,p ))%p
H,W,A,B=map(int, input().split())
p=10**9+7
ans=0
X=[1] #階乗テーブル
for i in range(1,H+W-1):
X+=[ (X[-1]*i) %p ]
Y=[1]*(H+W-1) #階乗の逆元テーブル
Y[H+W-2]=power_func(X[H+W-2],p-2,p)
for i in range(H+W-3,-1,-1):
Y[i]=Y[i+1]*(i+1) %p
for i in range(B,W):
ans+=(X[H-A-1+i]*X[A+W-2-i]*Y[H-A-1]*Y[i]*Y[A-1]*Y[W-1-i])%p
print(ans%p) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s370159088 | p04046 | Accepted | from math import factorial
H,W,A,B=map(int, input().split())
p=10**9+7
ans=0
X=[1,1] #階乗テーブル
Y=[1,1] #階乗の逆元テーブル
calc=[0,1] #逆元計算用テーブル
for i in range( 2, H+W-2 ):
X.append( ( X[-1] * i ) % p )
calc.append( ( -calc[p % i] * (p//i) ) % p )
Y.append( (Y[-1] * calc[-1]) % p )
for i in range(B,W):
ans+=(X[H-A-1+i]*X[A+W-2-i]*Y[H-A-1]*Y[i]*Y[A-1]*Y[W-1-i])%p
print(ans%p) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s536736075 | p04046 | Accepted | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""042-d"""
import sys
def factorialMod(x, mod):
"""Calculate modulo of funcotial 'x'."""
assert isinstance(x, int)
assert x >= 0
assert isinstance(mod, int)
assert mod >= 0
if x == 0:
return 1
return (x % mod) * factorialMod(x - 1, mod)
def binpow(p, e):
"""Bisection exponentiation."""
assert isinstance(e, int)
assert e >= 0
a = 1
while e:
if e % 2 == 0:
p = p * p
e /= 2
else:
a = a * p
e = e - 1
return a
def main():
"""Main function."""
mod = 1000000007
H, W, A, B = map(int, sys.stdin.readline().split())
fact_table = [1, 1]
[fact_table.append((fact_table[-1] * i) % mod) for i in range(2, H + W - 1)]
inv_fact_table = [pow(fact_table[i], 1000000005, 1000000007) for i in range(H + W - 1)]
# print(inv_fact_table)
def comb(n, r):
"""Calculate combination."""
assert n >= r and n >= 0 and r >= 0
return fact_table[n] * inv_fact_table[r] * inv_fact_table[n - r] % mod
result = sum([comb(H - A + i - 1, H - A -1) * comb(W + A - i - 2, A - 1) for i in range(B, W)]) % mod
print(result)
if __name__ == '__main__':
sys.exit(main()) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s042843726 | p04046 | Accepted | H,W,A,B= map(int, input().split())
mod = 10**9+7
N=W-B
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, H+W-2 ):
g1.append( ( g1[-1] * i ) % mod )
inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
g2.append( (g2[-1] * inverse[-1]) % mod )
#以下のcom関数を用いて組み合わせを計算
def com(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
ANS=0
for i in range(N):
ANS=(ANS+com(H-A-1+B,B+i, mod)*com(W+A-1-B,A+i, mod))%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 bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s009479592 | p04046 | Accepted |
class Combination:
def __init__(self, mod):
self.mod = mod
self.fact = [1] * (2 * 10 ** 5 + 1)
for i in range(1, 2 * 10 ** 5 + 1):
self.fact[i] = i * self.fact[i - 1] % self.mod
def nCr(self, n, k):
a = self.fact[n] % self.mod
b = (self.fact[k] * self.fact[n - k]) % self.mod
c = pow(b, self.mod - 2, self.mod)
return a * c % self.mod
def main():
H, W, A, B = map(int, input().split())
MOD = 10 ** 9 + 7
c = Combination(mod=MOD)
ans = 0
for i in range(W - B):
h, w = H - A - 1, B + i
a = c.nCr(h + w, h) % MOD
h, w = A - 1, W - B - i - 1
b = c.nCr(h + w, h) % MOD
ans = (ans + a * b) % MOD
print(ans % MOD)
if __name__ == '__main__':
main()
| 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s040692862 | p04046 | Accepted | mod = 10**9+7
H, W, A, B = list(map(int, input().split(" ")))
fact = [1] * (2 * 10**5+1)
for i in range(1, 2*10**5+1):
fact[i] = i * fact[i-1] % mod
def comb(n, k):
a = fact[n] % mod
b = (fact[k] * fact[n-k]) % mod
b_ = pow(b, mod-2, mod)
return (a * b_) % mod
ans = 0
for i in range(B, W):
# (h-a+i)Ci * (a+W-i)Ca
ans += comb(H-A+i-1, i) * comb(A+W-i-2, A-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 bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s787049394 | p04046 | Accepted | import operator as op
from functools import reduce
from math import factorial
import sys
modulus = 1000000007
factorial = [1, 1]
for i in range(2, 2000001):
factorial.append(factorial[-1] * i % modulus)
factorial_inv_rev = [pow(factorial[-1], 1000000005, modulus)]
for i in range(len(factorial)-1, 1, -1):
factorial_inv_rev.append(factorial_inv_rev[-1] * i % modulus)
def ncr(n, r):
if n==r or r==0:
return 1
else:
numelator = factorial[n]
denominator = factorial_inv_rev[-r] * factorial_inv_rev[r-n]
return numelator * denominator % modulus
h, w, a, b = map(int, input().split())
points = [(i, j) for i, j in zip(range(h-a-1, -1, -1), range(b, w))]
former = [ncr(i+j, i) for i, j in points]
latter = [ncr(h-i-1+w-j-1, h-i-1) for i, j in points]
print(sum(f*l for f, l in zip(former, latter)) % modulus) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s320667884 | p04046 | Accepted | MOD = 10**9+7
def add(a,b):
return (a+b) % MOD
def mul(a,b):
return (a*b) % MOD
def pow(a,n):
ans = 1
mag = a
for b in reversed(str(bin(n))):
if b == 'b': break
if b == '1':
ans = mul(ans, mag)
mag = mul(mag, mag)
return ans
def inv(a):
return pow(a, MOD-2)
H,W,A,B = map(int,raw_input().split())
factorical = [1]
factorical_inv = [1]
for n in range (1,H+W+1):
f = mul(factorical[n-1], n)
factorical.append(f)
if(n <= max(H,W)):
factorical_inv.append(inv(f))
def ncr(n,r):
return mul(mul(factorical[n], factorical_inv[n-r]), factorical_inv[r])
def paths(w,h):
return ncr(w+h,w)
ans = 0
for i in range(W-B):
p = mul(paths(H-A-1, B+i), paths(A-1, W-B-1-i))
ans = add(ans, p)
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 bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s609950436 | p04046 | Accepted | from sys import stdin, stdout, stderr
mod = 10**9 + 7
def solve():
def binom(n, k):
res = (modfact[n] * factinv[k]) % mod
res = (res * factinv[n - k]) % mod
return res
h, w, a, b = map(int, input().split())
ans = 0
modfact = [1] * (h + w)
factinv = [1] * (h + w)
for i in range(1, h + w):
modfact[i] = (i * modfact[i - 1]) % mod
factinv[i] = (pow(i, mod - 2, mod) * factinv[i - 1]) % mod
for i in range(h - a):
ans += (binom(b + i - 1, i) * binom(w + h - b - i - 2, h - i - 1)) % mod
ans %= mod
print(ans)
if __name__ == '__main__':
solve() | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s297984459 | p04046 | Accepted | mod = 10**9+7
H, W, A, B = [int(_) for _ in input().split()]
fact = [1] * (2 * 10**5+1)
for i in range(1, 2*10**5+1):
fact[i] = i * fact[i-1] % mod
def comb(n, k):
a = fact[n] % mod
b = (fact[k] * fact[n-k]) % mod
b_ = pow(b, mod-2, mod)
return (a * b_) % mod
ans = 0
for w in range(B, W):
ans += comb(H-A-1 + w, w) * comb(A-1 + W-w-1, W-w-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 bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s695750896 | p04046 | Accepted | C = int(1e9) + 7
H, W, A, B = map(int, input().split())
fact = [1]
for x in range(1, H + W - 2):
fact.append( (x * fact[x-1]) % C )
factinv = [1] * (H + W -2)
factinv[H + W - 3] = pow(fact[H + W -3], C-2, C)
for x in reversed(range(2, H + W -3)):
factinv[x] = ( factinv[x+1] * (x+1) ) % C
def nCr(n,r):
return ( fact[n] * factinv[r] * factinv[n-r] ) % C
ans = 0
for i in range(B,W):
ans = (ans + nCr(i+H-A-1, H-A-1) * nCr(A-1+W-i-1, A-1)) % C
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 bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s098204449 | p04046 | Accepted | h,w,a,b=map(int,raw_input().split(' '))
mod=1000000007
inv=[0]*(h+w)
fact=[0]*(h+w)
def ex(x,y):
if y==0: return 1
elif y==1: return x%mod
elif y%2==0: return ex(x,y/2)**2%mod
else: return ex(x,y/2)**2*x%mod
#factorial
fact[0]=1
for j in range(1,h+w):
fact[j]=fact[j-1]*j%mod
inv[h+w-1]=ex(fact[h+w-1],mod-2)
for j in reversed(range(h+w-1)):
inv[j]=inv[j+1]*(j+1)%mod
def nck(x,y):
return fact[x]*inv[y]*inv[x-y]%mod
su=0
for j in range(h-a):
su=(su+nck(b-1+j,b-1)*nck(h-1-j+w-1-b,w-1-b))%mod
print su | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s365983865 | p04046 | Accepted | H, W, A, B = map(int, input().split())
class Combin(object):
def __init__(self, max_n, mod = 10**9 + 7):
self.max_n = max_n
self.mod = mod
self.fac = self._init_factorials()
self.inv = self._init_inv()
def _init_factorials(self):
N = self.max_n
mod = self.mod
f = 1
fac = [1] * (N + 1)
for i in range(1, N + 1):
f *= i
f %= mod
fac[i] = f
return fac
def _init_inv(self):
N = self.max_n
mod = self.mod
ret = pow(self.fac[N], mod - 2, mod)
inv = [1] * (N + 1)
inv[N] = ret
for i in range(N-1, 0, -1):
ret *= i + 1
ret %= mod
inv[i] = ret
return inv
def nCb(self, n, b):
return (self.fac[n] * self.inv[b] * self.inv[n-b]) % self.mod
def solve(H, W, A, B):
mod = 10 ** 9 + 7
cb = Combin(H + W)
ans = cb.nCb(H + W - 2, H - 1)
t1 = B + H - 1
t2 = B - 1
t3 = W - B - 2
t4 = W - B - 1
for a in range(1, A + 1):
d = cb.nCb(t1 - a, t2) * cb.nCb(t3 + a, t4)
ans -= d
ans %= mod
return ans
print(solve(H, W, A, B)) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s008256714 | p04046 | Accepted | C = int(1e9) + 7
h, w, a, b = [int(x) for x in input().split()]
fact = [1]
for x in range(1, h + w - 2):
fact.append((x * fact[x - 1]) % C)
factinv = [1] * (h + w - 2)
factinv[h + w - 3] = pow(fact[h + w - 3], C - 2, C)
for x in reversed(range(2, h + w - 3)):
factinv[x] = (factinv[x + 1] * (x + 1)) % C
def nCr(n, r):
return (fact[n] * factinv[r] * factinv[n - r]) % C
ans = 0
for i in range(b, w):
ans = (ans + nCr(i + h - a - 1, h - a - 1) * nCr(a - 1 + w - i - 1, a - 1)) % C
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 bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s429379172 | p04046 | Accepted | M=10**9+7;H,W,A,B=map(int,input().split());Z=C=1
for I in range(H-1):Z=C=C*(W+H-B-2-I)*pow(I+1,M-2,M)%M
for I in range(1,H-A):C=C*(B-1+I)*(H-I)*pow(I*(W+H-B-1-I),M-2,M)%M;Z+=C
print(Z%M) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s690909960 | p04046 | Accepted | M=10**9+7;F=lambda X:pow(X,M-2,M);H,W,A,B=map(int,input().split());Z=C=1
for I in range(H-1):Z=C=C*(W+H-B-2-I)*F(I+1)%M
for I in range(1,H-A):C=C*(B-1+I)*(H-I)*F(I*(W+H-B-1-I))%M;Z+=C
print(Z%M) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s838503748 | p04046 | Accepted | M=10**9+7;F=lambda X:pow(X,M-2,M);H,W,A,B=map(int,input().split());Z=C=1
for I in range(H-1):Z=C=C*(W+H-B-2-I)*F(I+1)%M
for I in range(1,H-A):C=C*(B-1+I)*(H-I)%M*F(I*(W+H-B-1-I))%M;Z=(Z+C)%M
print(Z) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s208681054 | p04046 | Accepted | M=10**9+7;F=lambda X:pow(X,M-2,M);H,W,A,B=map(int,input().split());Z=C=1
for I in range(H-1):Z=C=C*(W+H-B-2-I)*F(I+1)%M
for I in range(1,H-A):C=C*(B-1+I)*(H-I)*F(I*(W+H-B-1-I))%M;Z=(Z+C)%M
print(Z) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s837370264 | p04046 | Accepted | M=10**9+7;F=[pow(X,M-2,M)for X in range(2*10**5)];H,W,A,B=map(int,input().split());Z=C=1
for I in range(H-1):Z=C=C*(W+H-B-2-I)*F[I+1]%M
for I in range(1,H-A):C=C*(B-1+I)*F[I]*(H-I)*F[W+H-B-1-I]%M;Z=(Z+C)%M
print(Z) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s017148839 | p04046 | Accepted | M=10**9+7;F=lambda X:pow(X,M-2,M);H,W,A,B=map(int,input().split());Z=C=1
for I in range(H-1):Z=C=C*(W+H-B-2-I)*F(I+1)%M
for I in range(1,H-A):C=C*(B-1+I)*F(I)*(H-I)*F(W+H-B-1-I)%M;Z=(Z+C)%M
print(Z) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s279500873 | p04046 | Accepted | F=lambda X:pow(X,M-2,M);M=10**9+7;H,W,A,B=map(int,input().split());Z=C=1
for I in range(min(W-1-B,H-1)):Z=C=C*(W+H-B-2-I)*F(I+1)%M
for I in range(1,H-A):C=C*(B-1+I)*F(I)*(H-I)*F(W+H-B-1-I)%M;Z=(Z+C)%M
print(Z) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s582303315 | p04046 | Accepted | def Combination_mod(n, k):
ret = f[n]
ret = (ret * finv[k]) % mod
ret = (ret * finv[n - k]) % mod
return ret
mod = 1000000007
h, w, a, b = map(int,input().split())
x = []
xi = b
xj = h - a - 1
while xi < w and xj >= 0:
x.append([xi, xj])
xi += 1
xj -= 1
n = w + h
f = [0] * n
finv = [0] * n
f[0] = 1
finv[0] = finv[1] = 1
for i in range(1, n):
f[i] = (f[i - 1] * i) % mod
finv[n - 1] = pow(f[n - 1], mod - 2, mod)
for i in range(n - 2, 1, -1):
finv[i] = ((i + 1) * finv[i + 1]) % mod
ans = 0
for i, j in x:
ans1 = Combination_mod(i + j, i)
ans1 *= Combination_mod(w - 1 - i + h - 1 - j, w - 1 - i)
ans += ans1
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 bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s316420238 | p04046 | Runtime Error | # coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
import copy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)
def lcm(a, b): return a * b / gcd(a, b)
# 1 2 3
# a, b, c = LI()
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
# a = I()
def I(): return int(sys.stdin.buffer.readline())
# abc def
# a, b = LS()
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
# a = S()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
# 2
# 1
# 2
# [1, 2]
def IR(n): return [I() for i in range(n)]
# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]
def LIR(n): return [LI() for i in range(n)]
# 2
# abc
# def
# [abc, def]
def SR(n): return [S() for i in range(n)]
# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]
def LSR(n): return [LS() for i in range(n)]
# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]
def SRL(n): return [list(S()) for i in range(n)]
n, k = LI()
d = LI()
limit = 11*n
while n < limit:
flg = 1
for x in list(str(n)):
if int(x) in d:
flg = 0
break
if flg:
print(n)
break
n += 1 | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s670718509 | p04046 | Runtime Error | from sys import stdin, stdout
from time import perf_counter
import sys
sys.setrecursionlimit(10**9)
mod = 10**9+7
# import sys
# sys.stdout = open("e:/cp/output.txt","w")
# sys.stdin = open("e:/cp/input.txt","r")
n,k = map(int,input().split())
d= list(map(int,input().split()))
test = [1,2,3,4,5,6,7,8,9]
for item in range(k):
if d[item]==0:
print(n)
exit()
result =[]
for item in test:
if item not in d:
result.append(item)
n= list(str(n))
# final_result =[]
for item in range(len(n)):
if int(n[item])>0:
if n[item] != result[item]:
n[item] = str(result[item])
ans = "".join(n)
print(ans)
| 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s282585295 | p04046 | Runtime Error | from sys import stdin, stdout
from time import perf_counter
import sys
sys.setrecursionlimit(10**9)
mod = 10**9+7
n,k = map(int,input().split())
d= list(map(int,input().split()))
test = [1,2,3,4,5,6,7,8,9]
for item in range(k):
if d[item]==0:
print(n)
exit()
result =[]
for item in test:
if item not in d:
result.append(item)
n= list(str(n))
# final_result =[]
for item in range(len(n)):
if int(n[item])>0:
if n[item] != result[item]:
n[item] = str(result[item])
ans = "".join(n)
print(ans)
| 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s680323602 | p04046 | Runtime Error | P = 10**9+7
fac = [1]
ifac = [1]
ff = 1
for i in range(1,200001):
ff *= i
ff %= p
fac.append(ff)
ifac.append(pow(ff, p-2, p))
def ncr(n, r, p):
return (fac[n] * ifac[r] % p * ifac[n-r] % p);
h,w,a,b = map(int,input().split())
s = 0
nC = b-1
kC = 0
nD = w-b-1+h-1
kD = h-1
for i in range(h-a):
C = ncr(nC, kC, P)
D = ncr(nD, kD, P)
s = (s + C * D) % P
nC += 1
kC += 1
kD -= 1
nD -= 1
print(s)
| 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s728668182 | p04046 | Runtime Error | import sys
def input(): return sys.stdin.readline().strip()
mod = 10**9+7
class Combination:
"""
O(n)の前計算を1回行うことで,O(1)でnCr mod mを求められる
n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
使用例:
comb = Combination(1000000)
print(comb(5, 3)) # 10
"""
def __init__(self, n_max, mod=10**9+7):
self.mod = mod
self.modinv = self.make_modinv_list(n_max)
self.fac, self.facinv = self.make_factorial_list(n_max)
def __call__(self, n, r):
return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod
def make_factorial_list(self, n):
# 階乗のリストと階乗のmod逆元のリストを返す O(n)
# self.make_modinv_list()が先に実行されている必要がある
fac = [1]
facinv = [1]
for i in range(1, n+1):
fac.append(fac[i-1] * i % self.mod)
facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
return fac, facinv
def make_modinv_list(self, n):
# 0からnまでのmod逆元のリストを返す O(n)
modinv = [0] * (n+1)
modinv[1] = 1
for i in range(2, n+1):
modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
return modinv
comb = Combination(10**5)
def main():
H, W, A, B = map(int, input().split())
ans = 0
for i in range(1, H - A + 1):
ans += comb(i + B - 2, i - 1) * comb(H - i + W - B - 1, H - i)
ans %= mod
print(ans)
if __name__ == "__main__":
main()
| 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s448115246 | p04046 | Runtime Error | H, W, A, B = map(int, open(0).read().split())
MOD = 10**9+7
def modperm(m, n, mod):
p = 1
for i in range(n):
p = p * (m - i) % mod
return p
def modcomb(m, n, mod):
if n > m - n:
n = m - n
p = modperm(m, n, mod)
q = pow(modperm(n, n, mod), -1, mod)
return p * q % mod
total = modcomb(H + W - 2, W - 1, MOD)
tmp = modcomb(A + W - 2, W - 1, MOD)
total -= tmp
for i in range(B - 1):
a = H - A + i
b = i + 1
c = W - i - 1
d = W + A - 2 - i
# print(a,b,c,d)
tmp = tmp * a * c % MOD
tmp = tmp * pow(b, MOD - 2, MOD) % MOD
tmp = tmp * pow(d, MOD - 2, MOD) % MOD
# print(tmp)
total = (total - tmp) % MOD
print(total) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s641090957 | p04046 | Runtime Error | from operator import mul
from functools import reduce
from scipy.special import comb
# def cmb(n, r, mod):
# if ( r<0 or r>n ):
# return 0
# r = min(r, n-r)
# return g1[n] * g2[r] * g2[n-r] % mod
# def cmb(n, r):
# r = min(n-r, r)
# if r == 0:
# return 1
# over = reduce(mul, range(n, n - r, -1))
# under = reduce(mul, range(1, r + 1))
# return over // under
hwab = list(map(lambda x: int(x), input().split(" ")))
h = hwab[0]
w = hwab[1]
a = hwab[2]
b = hwab[3]
mod = 10**9 + 7
res = 0
for i in range(h-a):
res += comb(b+i-1, i) * comb(w-b+h-i-2, h-i-1)
print(int(res) % mod)
| 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s755233800 | p04046 | Runtime Error | hwab = list(map(lambda x: int(x), input().split(" ")))
h = hwab[0]
w = hwab[1]
a = hwab[2]
b = hwab[3]
mod = 10**9 + 7
res = 0
for i in range(h-a):
res += comb(b+i-1, i) * comb(w-b+h-i-2, h-i-1)
print(res % mod)
| 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s429006145 | p04046 | Runtime Error | def main():
import math
h,w,a,b=map(int,input().split())
h-=1
w-=1
a-=1
b-=1
N=math.factorial(w-b-1+h)/math.factorial(h)/math.factorial(w-b-1)
h1=h-1
while h1>a:
z=h-h1+b
z1=w-b-1+h1
N+=math.factorial(z)/math.factorial(h-h1)/math.factorial(b)*math.factorial(z1)/math.factorial(w-b-1)/math.factorial(h1)
h1-=1
print(int(N%(10**9+7)))
if __name__=="__main__":
main()
| 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s847675542 | p04046 | Runtime Error | a,b=map(int,input().split())
fac=[0]*200001#iの階乗mod(1000000007)
inv=[0]*200001#iの逆元mod(1000000007)
fac[0]=1
ans=0
for i in range(1,200001):
fac[i]=fac[i-1]*i%1000000007
inv[200000]=pow(fac[200000],1000000005,1000000007)
for i in range(199999,0,-1):
inv[i]=(inv[i+1]*(i+1))%1000000007
inv[0]=1
for i in range(h-a):
if i==0:
if h==1:
x=1
else:
x=(fac[w-b+h-2
-i]*inv[w-1-b]*inv[h-1-i])%1000000007
elif w==b+1:
x=(fac[b-1+i]*inv[b-1]*inv[i])%1000000007
else:
x=((fac[b-1+i]*inv[b-1]*inv[i])%1000000007)*((fac[w-b+h-2-i]*inv[w-b-1]*inv[h-1-i])%1000000007)
ans=(ans+x)%1000000007
print(ans) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s447961783 | p04046 | Runtime Error | import math
def combinations_count(n, r):
return math.factorial(n+r) // (math.factorial(n) * math.factorial(r))
H, W, A, B = list(map(int, input().split()))
ans = 0
for i in range(H-A):
ans += combinations_count(B-1, i) * combinations_count(W-B-1, H-1-i)
print(int(ans%(1e+9 + 7))) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s768002776 | p04046 | Runtime Error | H, W, A, B = map(int, input().split())
N = 10**9 + 7
def factor(n,k):
assert n>=k
if n == k:
return 1
else:
return n*factor(n-1,k)
def comb(n,k):
if k < n/2:
return int(factor(n,n-k) / factor(k,0))
else:
return int(factor(n,k) / factor(n-k,0))
result = 0
for i in range(min(H-A, W-B)+1):
f1 = comb(B+H-A, B+i) % N
f2 = comb(W-B+A, A+i) % N
result += f1 * f2
print(result % N)
| 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s933727690 | p04046 | Runtime Error | def irohamasu(i, j, H, W, A, B):
if (i >= H - A) and (j <= B - 1):
return 0
elif i == 0 & j == 0:
return 1
elif i == 0:
return irohamasu(i, j-1, H, W, A, B)
elif j == 0:
return irohamasu(i-1, j, H, W, A, B)
else:
return (irohamasu(i-1, j, H, W, A, B) + irohamasu(i, j-1, H, W, A, B))
H, W, A, B = map(int, input().split())
answer = irohamasu(H-1, W-1, H, W, A, B)
print(answer % (10**9 + 7)) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s726350375 | p04046 | Runtime Error |
import math
def re_factorial(n, r):
if n <= r:
return 1
return n * re_factorial(n-1,r)
H, W, A, B = map(int, input().split())
y = H - A - 1
ans = 0
for dx in range(B+1,W+1):
x = W - dx
if y >= dx-1:
xn = re_factorial(dx-1,1)
nn = re_factorial(dx-1+y, y)
Ansn = nn / xn
if x >= A-1:
ym = re_factorial(A-1,1)
mm = re_factorial(x+A-1,x)
Ansm = mm / ym
else:
xm = re_factorial(x,1)
mm = re_factorial(x+A-1,A-1)
Ansm = mm / xm
else:
yn = re_factorial(y,1)
nn = re_factorial(dx-1+y, dx-1)
Ansn = nn / yn
if x >= A-1:
ym = re_factorial(A-1,1)
mm = re_factorial(x+A-1,x)
Ansm = mm / ym
else:
xm = re_factorial(x,1)
mm = re_factorial(x+A-1,A-1)
Ansm = mm / xm
ans += Ansn * Ansm
ans = int(ans)%1000000007
print(int(ans)) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s320744238 | p04046 | Runtime Error | import math
H, W, A, B = map(int, input().split())
y = H - A -1
ans = 0
for x in range(B,W):
yn = math.factorial(y)
xn = math.factorial(x)
nn = math.factorial(y+x)
Ansn = nn / (xn * yn)
xm = math.factorial(W-x-1)
ym = math.factorial(A-1)
mm = math.factorial(W-x-1+A-1)
Ansm = mm / (xm * ym)
ans += Ansn * Ansm
ans = ans%1000000007
print(int(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 bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s215993841 | p04046 | Runtime Error | def cmb(n, r, mod):
if ( r<0 or r>n ):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7
size = 10**4
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range( 2, size + 1 ):
g1.append( ( g1[-1] * i ) % mod )
inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
g2.append( (g2[-1] * inverse[-1]) % mod )
H, W, A, B = map(int,input().split())
ans = 0
for i in range(W-B):
ans += cmb(H-A-1+(B+i), B+i, mod) * cmb(A-1+W-B-1-i, A-1, mod)
ans %= mod
print(ans) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s291695475 | p04046 | Runtime Error | mod = 1000000007
H, W, A, B = map(int, input().split())
factorial = [1]
for n in range(1, H+W):
factorial.append(factorial[n-1]*n%mod)
def power(x, y):
if y == 0:
return 1
elif y == 1:
return x % mod
elif y % 2 == 0:
return power(x, y/2)**2 % mod
else :
return power(x, y/2)**2 * x % mod
inverseFactorial = [0] * (H+W)
inverseFactorial[H+W-1] = power(factorial[H+W-1], mod-2)
for n in range(H+W-2, -1, -1):
inverseFactorial[n] = inverseFactorial[n+1] * (n+1) % mod
def combi(n, m):
return factorial[n] * inverseFactorial[m] * inverseFactorial[n-m] % mod
sum = 0
for i in range(B+1, W+1):
sum = (sum + combi(H-A-1+i-1, i-1) * combi(A-1+W-i, W-i)) % mod
print(sum) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s599821710 | p04046 | Runtime Error | import math
h,w,a,b = map(int, input().split())
result = 0
for i in range(b,w):
result += ((math.factorial((i)+(h-a-1))) / (math.factorial(i) * math.factorial(h-a-1))) * ((math.factorial((w-i-1)+(a-1))) / (math.factorial(w-i-1)*math.factorial(a-1)))
result = int(result%(10**9 + 7))
print(result) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s550946411 | p04046 | Runtime Error | h, w, a, b = map(int, input().split())
mod = 10 ** 9 + 7
n = h + w
f = [1 for _ in range(n)]
for i in range(1, n):
f[i] = f[i-1] * i
def f_inv(x):
return pow(f[x], mod-2, mod)
def comb(n, k):
return (f[n] * f_inv[k] % mod) * f_inv[n-k] % mod
ans = comb(h+w-2, h-1)
for i in range(b):
print(h-a+i, i)
print(a+w-i-2, a-1)
ans -= comb(h-a+i-1, i) * comb(a+w-i-2, a-1) % mod
ans %= mod
print(ans) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s843052367 | p04046 | Runtime Error | #Iroha and a grid
#abc 042
h,w,a,b=map(int,input().split())
mod=10**9+7
def dp(x,y,h,w,a,b):
if x==-2:
c=1
else:
if x==w-1 and y==h-1:
return 1
if x>=w or y>=h or (x<b and y>=h-a):
return 0
ans=dp(x+1,y,h,w,a,b)+dp(x,y+1,h,w,a,b)
return ans
print(dp(0,0,h,w,a,b)%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 bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s076339125 | p04046 | Runtime Error | #Iroha and a grid
#abc 042
h,w,a,b=map(int,input().split())
mod=10**9+7
def dp(x,y,h,w,a,b):
if x==-2:
c=1
else:
if x==w-1 and y==h-1:
return 1
if x>=w or y>=h or (x<b and y>=h-a):
return 0
ans=dp(x+1,y,h,w,a,b)+dp(x,y+1,h,w,a,b)
return ans
print(dp(0,0,h,w,a,b)%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 bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s278222990 | p04046 | Runtime Error | #Iroha and a grid
#abc 042
h,w,a,b=map(int,input().split())
mod=10**9+7
memo={}
def dp(x,y,h,w,a,b):
if (x,y) in memo:
return memo[(x,y)]
else:
if x==w-1 and y==h-1:
return 1
if x>=w or y>=h or (x<b and y>=h-a):
return 0
ans=dp(x+1,y,h,w,a,b)+dp(x,y+1,h,w,a,b)
memo[(x,y)]=ans
return memo[(x,y)]
ans=dp(0,0,h,w,a,b)%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 bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s553943529 | p04046 | Runtime Error | #Iroha and a grid
#abc 042
h,w,a,b=map(int,input().split())
mod=10**9+7
memo={}
def dp(x,y,h,w,a,b):
if (x,y) in memo:
return memo[(x,y)]
else:
if x==w-1 and y==h-1:
return 1
if x>=w or y>=h or (x<b and y>=h-a):
return 0
ans=dp(x+1,y,h,w,a,b)+dp(x,y+1,h,w,a,b)
memo[(x,y)]=ans
return memo[(x,y)]
print(dp(0,0,h,w,a,b)%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 bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s033577118 | p04046 | Runtime Error | n,k = map(int,input().rstrip().split())
dislikes = list(map(int,input().rstrip().split()))
n = str(n)
len_n = len(n)
separate_n = [int(s) for s in n]
pay = separate_n.copy()
up_nextlevel = False
for i in range(len(separate_n)-1,-1,-1):
up_nextlevel = False
if separate_n[i] in dislikes:
for j in range(10):
num = separate_n[i]+j
if num > 9:
num -= 10
up_nextlevel = True
if not(num in dislikes):
pay[i] = num
break
else:
continue
if up_nextlevel:
for i in range(1,10):
if not(i in dislikes):
print(i,end="")
break
for p in pay:
print(p,end="") | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s469438602 | p04046 | Runtime Error | from math import factorial
h,w,a,b = map(int,input().split())
sg = 0
i = 0 #場合分け
svi = factorial(i+b)/factorial(i)/factorial(b)
vig = factorial(h-i-1+w-b-1)/factorial(h-i-1)/factorial(w-b-1)
sg = sg + svi*vig
# 1<= i <= h-a の時
for i in range(1,h-a):
svj = svi = factorial(i-1+b)/factorial(i-1)/factorial(b)
svi = factorial(i+b)/factorial(i)/factorial(b)
vig = factorial(h-i-1+w-b-1)/factorial(h-i-1)/factorial(w-b-1)
sg = sg + (svi-svj)*vig
print(int(sg%(10**9+7))) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s712199502 | p04046 | Runtime Error | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, radians, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
lim = 2*10**5 #必要そうな階乗の限界を入力
#階乗#
fact = [1] * (lim+1)
for n in range(1, lim+1):
fact[n] = n * fact[n-1] % mod
#階乗の逆元#
fact_inv = [1]*(lim+1)
fact_inv[lim] = pow(fact[lim], mod-2, mod)
for n in range(lim, 0, -1):
fact_inv[n-1] = n*fact_inv[n]%mod
def C(n, r):
return (fact[n]*fact_inv[r]%mod)*fact_inv[n-r]%mod
H, W, A, B = MAP()
ans = 0
for n in range(B, W):
way = C(H-A-1+n, n)*C(W-n-1+A-1, A-1)%mod
ans = (ans+way)%mod
print(ans)
| 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s146624685 | p04046 | Runtime Error | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
lim = 2*10**5 #必要そうな階乗の限界を入力
#階乗#
fact = [1] * (lim+1)
for n in range(1, lim+1):
fact[n] = n * fact[n-1] % mod
#階乗の逆元#
fact_inv = [1]*(lim+1)
fact_inv[lim] = pow(fact[lim], mod-2, mod)
for n in range(lim, 0, -1):
fact_inv[n-1] = n*fact_inv[n]%mod
def C(n, r):
return (fact[n]*fact_inv[r]%mod)*fact_inv[n-r]%mod
H, W, A, B = MAP()
ans = 0
for n in range(B, W):
way = C(H-A-1+n, n)*C(W-n-1+A-1, A-1)%mod
ans = (ans+way)%mod
print(ans)
| 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s993478612 | p04046 | Runtime Error | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
lim = 2*10**5 #必要そうな階乗の限界を入力
#階乗#
fact = [1] * (lim+1)
for n in range(1, lim+1):
fact[n] = n * fact[n-1] % mod
#階乗の逆元#
fact_inv = [1]*(lim+1)
fact_inv[lim] = pow(fact[lim], mod-2, mod)
for n in range(lim, 0, -1):
fact_inv[n-1] = n*fact_inv[n]%mod
def C(n, r):
return (fact[n]*fact_inv[r]%mod)*fact_inv[n-r]%mod
H, W, A, B = MAP()
ans = 0
for n in range(B, W):
way = C(H-A-1+n, n)*C(W-n-1+A-1, A-1)%mod
ans = (ans+way)%mod
print(ans) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s020909568 | p04046 | Runtime Error | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
lim = 2*10**5 #必要そうな階乗の限界を入力
#階乗#
fact = [1] * (lim+1)
for n in range(1, lim+1):
fact[n] = n * fact[n-1] % mod
#階乗の逆元#
fact_inv = [1]*(lim+1)
fact_inv[lim] = pow(fact[lim], mod-2, mod)
for n in range(lim, 0, -1):
fact_inv[n-1] = n*fact_inv[n]%mod
def C(n, r):
return (fact[n]*fact_inv[r]%mod)*fact_inv[n-r]%mod
H, W, A, B = MAP()
ans = 0
for n in range(B, W):
way = C(H-A-1+n, n)*C(W-n-1+A-1, A-1)%mod
ans = (ans+way)%mod
print(ans) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s563818377 | p04046 | Runtime Error | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
def pow(x, n, p):
tmp = 1
while n:
if n%2:
tmp = tmp*x%mod
x = x*x%mod
n >>= 1
return tmp%mod
print(pow(2, 10, mod))
lim = 2*10**5 #必要そうな階乗の限界を入力
#階乗#
fact = [1] * (lim+1)
for n in range(1, lim+1):
fact[n] = n * fact[n-1] % mod
#階乗の逆元#
fact_inv = [1]*(lim+1)
fact_inv[lim] = pow(fact[lim], mod-2, mod)
for n in range(lim, 0, -1):
fact_inv[n-1] = n*fact_inv[n]%mod
def C(n, r):
return (fact[n]*fact_inv[r]%mod)*fact_inv[n-r]%mod
H, W, A, B = MAP()
ans = 0
for n in range(B, W):
way = C(H-A-1+n, n)*C(W-n-1+A-1, A-1)%mod
ans = (ans+way)%mod
print(ans)
| 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s541449056 | p04046 | Runtime Error | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
lim = 2*10**5 #必要そうな階乗の限界を入力
#階乗#
fact = [1] * (lim+1)
for n in range(1, lim+1):
fact[n] = n * fact[n-1] % mod
#階乗の逆元#
fact_inv = [1]*(lim+1)
fact_inv[lim] = pow(fact[lim], mod-2, mod)
for n in range(lim, 0, -1):
fact_inv[n-1] = n*fact_inv[n]%mod
def C(n, r):
return (fact[n]*fact_inv[r]%mod)*fact_inv[n-r]%mod
H, W, A, B = MAP()
ans = 0
for n in range(B, W):
way = C(H-A-1+n, n)*C(W-n-1+A-1, A-1)%mod
ans = (ans+way)%mod
print(ans) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s290427555 | p04046 | Runtime Error | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
lim = 2*10**6
fact = [1]*(lim+1)
for n in range(1, lim+1):
fact[n] = n*fact[n-1]%mod
fact_inv = [1]*(lim+1)
fact_inv[lim] = pow(fact[lim], mod-2, mod)
for n in range(lim, 0, -1):
fact_inv[n-1] = n*fact_inv[n]%mod
def C(n, r):
return (fact[n]*fact_inv[r]%mod)*fact_inv[n-r]%mod
H, W, A, B = MAP()
ans = 0
for n in range(B, W):
way = C(H-A-1+n, n)*C(W-n-1+A-1, A-1)%mod
ans = (ans+way)%mod
print(ans)
| 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s242144826 | p04046 | Runtime Error | def func(i, j, h, w, a, b):
if j == 0:
return 1
elif i == 0:
if j < h - a:
return 1
else:
return 0
else:
if 0 < i < b and h - a <= j < h:
return 0
else:
return func(i-1, j, h, w, a, b) + func(i, j-1, h, w, a, b)
h, w, a, b = (int(x) for x in input().split())
y = func(w-1, h-1, h, w, a, b)
y = y % (1000000007)
print(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 bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s620083079 | p04046 | Runtime Error | import math
h,w,a,b=map(int, input().split())
def comb(n,r):
c=math.factorial(n)/(math.factorial(n-r)*math.factorial(r))
return c
def way_num(x, y):
return comb(x+y-2, x-1)
all_num=way_num(h, w)
no_num=0
for i in range(b):
to_here=way_num(h-a+1, i+1)
from_here=way_num(a, w-i)
if i>0:
overlap=way_num(h-a+1, i)*from_here
else:
overlap=0
no_num+=to_here*from_here-overlap
num=all_num-no_num
res=num%(10**9+7)
print(res) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s188214041 | p04046 | Runtime Error | h,w,a,b = map(int,input().split())
xList = list(range(w-b))
Py = h-a-1
mod = 10**9+7
def combination(x, y):
c = factorial(x)/(factorial(y)*factorial(x-y))
return c
def factorial(x):
f = 1
for i in range(1,x+1):
f *= i
return f
ans = 0
for x in xList:
Px = b+x
Gx = a+w-1-b-x
if x == 0:
buf = combination(Px+Py,Px)*combination(Gx,a)%mod
else:
buf = (combination(Px+Py,Px)-combination(Px+Py-1, Px-1))*combination(Gx,a)%mod
# print(Px,Py,Gx,a)
ans += buf
print(ans) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s434053541 | p04046 | Runtime Error | h,w,a,b = map(int,input().split())
xList = list(range(w-b))
Py = h-a-1
def combination(x, y):
c = factorial(x)/(factorial(y)*factorial(x-y))
return c
def factorial(x):
f = 1
for i in range(1,x+1):
f *= i
return f
ans = 0
for x in xList:
Px = b+x
Gx = a+w-1-b-x
if x == 0:
buf = combination(Px+Py,Px)*combination(Gx,a)
else:
buf = (combination(Px+Py,Px)-combination(Px+Py-1, Px-1))*combination(Gx,a)
# print(Px,Py,Gx,a)
ans += buf
print(ans%1000000007) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s330023849 | p04046 | Runtime Error | H,W,A,B=map(int,input().split())
M=H-A
N=W-B
import math
def comb(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
a=B-1
b=H+N-2
c=N-1
S=sum(comb(a+k,a)*(comb(b-i,c)%(10**+7) for k in range(M))
print(S%(10**9+7)) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s921265113 | p04046 | Runtime Error | H,W,A,B=map(int,input().split())
M=H-A
N=W-B
import math
def comb(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
a=B-1
b=H+N-2
c=N-1
S=sum(comb(a+k,a)*(comb(b-i,c) for k in range(M))
print(S%(10**9+7)) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s170327385 | p04046 | Runtime Error | H,W,A,B=map(int,input().split())
M=H-A
N=W-B
import math
def comb(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
a=B-1
b=H+N-2
c=N-1
S=sum(comb(a+k,a)*comb(b-i,c) for k in range(M))
print(S) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s169045602 | p04046 | Runtime Error | def fac(x):
y=1
for i in range(x):
y*=(i+1)
return(y)
def combi(i,j):
x=fac(i+j)/(fac(i)*fac(j))
return(int(x))
h,w,a,b=map(int,input().split())
ans=0
for i in range(w-b):
ans+=combi(b+i,h-a-1)*combi(w-b-i-1,a-1)
print(int(ans%(10**9+7))) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s663572790 | p04046 | Runtime Error | def fac(x):
y=1
for i in range(x):
y*=(i+1)
return(y)
def combi(i,j):
x=fac(i+j)/(fac(i)*fac(j))
return(int(x))
h,w,a,b=map(int,input().split())
all=combi(h-1,w-1)
z=[[0 for i in range(a)] for j in range(b)]
exc=0
for i in range(b):
for j in range(a):
if i==0:
z[i][j]=1
elif j==0:
z[i][j]=combi(h-a+j-1,i)+z[i-1][j]
else:
z[i][j]=z[i][j-1]+z[i-1][j]
for i in range(a):
exc+=z[b-1][i]*combi(a-i-1,w-b-1)
ans=all-exc
print(int(ans%(10**9+7))) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s863431271 | p04046 | Runtime Error | def fac(x):
y=1
for i in range(x):
y*=(i+1)
return(y)
def combi(i,j):
x=fac(i+j)/(fac(i)*fac(j))
return(x)
h,w,a,b=map(int,input().split())
all=combi(h-1,w-1)
exc=0
for i in range(a):
exc+=combi(a-1-i,b-1)*combi(i,w-b-1)
ans=all-exc
print(int(ans%(10^9+7)))
| 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s861402974 | p04046 | Runtime Error | H,W,A,B = map(int, input().split())
judge = (A+B)/(H+W)
a = H-A
res = 0
import math
def comba(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
if judge < 0.5:
base = comba((H+W-2), W-1, exact=True)
for i in range(1,B+1):
ex1 = comba(a-1+i-1,i-1)
ex2 = comba(A-1+W-i,W-i)
exres = ex1 *ex2
res = res + exres
result = (base -res) %1000000007
else:
for i in range(1,H-A+1):
ex1 = comba(i-1+B-1,i-1)
ex2 = comba(W-B-1+H-i,H-i)
exres = ex1 *ex2
res = res + exres
result = res %1000000007
print(result) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s375877240 | p04046 | Runtime Error | H,W,A,B = map(int, input().split())
a = H-A
res = 0
for i in range(1,B+1):
ex1 = comba(a-1+i-1,i-1)
print("ex1="+str(ex1))
ex2 = comba(A-1+W-i,W-i)
print("ex2="+str(ex2))
exres = ex1 *ex2
res = res + exres
result = (base -res) %1000000007
print(result) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s735200795 | p04046 | Runtime Error | #include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<tuple>
#include<vector>
#include<cstdlib>
#include<cstdint>
#include<stdio.h>
#include<cmath>
#include<limits>
#include<iomanip>
#include<ctime>
#include<climits>
#include<random>
#include<queue>
using namespace std;
template <class T> using V = vector<T>;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
const long long INF = 1LL << 60;
using ll = long long;
using db = long double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using graph = V<V<int>>;
using pq = priority_queue<ll>;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a);
#define ALL(a) (a).begin(),(a).end()
ll Sum(ll n) {
ll m=0;
while(n){
m+=n%10;
n/=10;
}
return m;
}
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void Comuse() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++){
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
#define comuse Comuse()
ll combi(int n, int k){
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll perm(int n,int k){
if(n < k) return 0;
if(n < 0 || k < 0) return 0;
return fac[n] * (finv[k] % MOD) % MOD;
}
ll modpow(ll a,ll n,ll mod){
ll ans=1;
while(n>0){
if(n&1){
ans=ans*a%mod;
}
a=a*a%mod;
n>>=1;
}
return ans;
}
ll modinv(ll a, ll mod) {
return modpow(a, mod - 2, mod);
}
ll modcombi(int n,int k,int mod){
ll ans=1;
for(ll i=n;i>n-k;i--){
ans*=i;
ans%=mod;
}
for(ll i=1;i<=k;i++){
ans*=modinv(i,mod);
ans%=mod;
}
return ans;
}
ll lcm(ll a,ll b){
ll n;
n=a/gcd(a,b)*b;
return n;
}
vll div(ll n){
vll ret;
for(ll i=1;i*i<=n;i++){
if(n%i==0){
ret.push_back(i);
if(i*i!=n){
ret.push_back(n/i);
}
}
}
SORT(ret);
return (ret);
}
vector<bool> isprime(MAX+100,true);
void primeuse(){
isprime[0]=false;
isprime[1]=false;
for(int i=2;i<MAX+50;i++){
int up=sqrt(i)+1;
for(int j=2;j<up;j++){
if(i%j==0){
isprime[i]=false;
}
}
}
}
void Solve();
const int MAX_N = 131072;
//segment tree
int NN;
int seg[MAX_N*2-1];
void seguse(){
for(int i=0;i<2*NN-1;i++){
seg[i]=INT_MAX;
}
}
signed main(){
cin.tie(0);
ios::sync_with_stdio(false);
cout<<setprecision(20)<<fixed;
Solve();
}
/****************************************\
| Thank you for viewing my code:) |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka |
\****************************************/
//segtreeの葉の先頭の添え字はN-1
void Solve(){
//ll N=262144;
//vll segtree(2*N-1);
ll n;
cin>>n;
vll A(n);
FOR(i,0,n){
cin>>A[i];
}
REV(A);
ll ans=0;
ll now=1;
FOR(i,0,n){
ans+=now*A[i];
if(A[i]<10){
now*=10;
}
else if(A[i]<100){
now*=100;
}
else if(A[i]<1000){
now*=1000;
}
else if(A[i]<10000){
now*=10000;
}
else{
now*=100000;
}
now%=MOD;
ans%=MOD;
}
cout<<ans<<"\n";
} | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s461626085 | p04046 | Runtime Error | # 解説を見て解いた。解説PDFの「B≦i≦Wを満たす全てのiについて」のWはW-1の間違い。
def make_table(h, w):
for i in range(1, h + w - 1):
fac_table.append(fac_table[-1] * i % mod) # i! mod 10**9+7
inv_table.append(pow(fac_table[-1], mod - 2, mod)) # (i!)^(-1) mod 10**9+7.
def comb(n, r):
return fac_table[n] * inv_table[n - r] * inv_table[r] % mod
def resolve():
H, W, A, B = map(int, input().split())
make_table(H, W)
_sum = 0
print(
sum(
[
comb(H - A - 1 + i, i) * comb(A - 1 + W - i - 1, A - 1) % mod
for i in range(B, W)
]
)
% mod
)
if __name__ == "__main__":
resolve() | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s957350133 | p04046 | Runtime Error | import math
h, w, a, b = map(int, input().split())
ans = 0
rp = [h-a-1, b]
def f(x):
if x == 0:
return 1
else:
a = 1
for i in range(1, x+1):
a *= i
return a
def c(x, y):
return f(x)/(f(y)*f(x-y))
sum = 0
while True:
x = c(rp[0]+rp[1], rp[0]) * c((h-rp[0]-1)+(w-rp[1]-1), h-rp[0]-1)
sum += x
if rp[0] <= 0 or rp[1] >= w-1:
break
rp[0] -= 1
rp[1] += 1
print(math.floor(sum)) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s083831303 | p04046 | Runtime Error | h, w, a, b = map(int, input().split())
ans = 0
rp = [h-a-1, b]
def f(x):
if x == 0:
return 1
else:
a = 1
for i in range(1, x+1):
a *= i
return a
def c(x, y):
return f(x)/(f(y)*f(x-y))
sum = 0
while True:
x = c(rp[0]+rp[1], rp[0]) * c((h-rp[0]-1)+(w-rp[1]-1), h-rp[0]-1)
sum += x
if rp[0] <= 0 or rp[1] >= w-1:
break
rp[0] -= 1
rp[1] += 1
print(sum) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s987187315 | p04046 | Runtime Error | from itertools import permutations
import sys
sys.setrecursionlimit(10 ** 6)
from bisect import *
from collections import *
from heapq import *
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def SI(): return sys.stdin.readline()[:-1]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
int1 = lambda x: int(x) - 1
def MI1(): return map(int1, sys.stdin.readline().split())
def LI1(): return list(map(int1, sys.stdin.readline().split()))
p2D = lambda x: print(*x, sep="\n")
dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]
# grobalにmdを設定すること
class mint:
def __init__(self, x):
self.__x = x % md
def __str__(self):
return str(self.__x)
def __neg__(self):
return mint(-self.__x)
def __add__(self, other):
if isinstance(other, mint): other = other.__x
return mint(self.__x + other)
def __sub__(self, other):
if isinstance(other, mint): other = other.__x
return mint(self.__x - other)
def __rsub__(self, other):
return mint(other - self.__x)
def __mul__(self, other):
if isinstance(other, mint): other = other.__x
return mint(self.__x * other)
__radd__ = __add__
__rmul__ = __mul__
def __truediv__(self, other):
if isinstance(other, mint): other = other.__x
return mint(self.__x * pow(other, md - 2, md))
def __rtruediv__(self, other):
return mint(other * pow(self.__x, md - 2, md))
def __pow__(self, power, modulo=None):
return mint(pow(self.__x, power, md))
md = 10**9+7
def nCr(com_n, com_r):
if com_n < com_r: return 0
return fac[com_n] * ifac[com_r] * ifac[com_n - com_r]
n_max = 100005
fac = [mint(1)]
for i in range(1, n_max + 1): fac.append(fac[-1] * i)
ifac = [mint(1)] * (n_max + 1)
ifac[n_max] /= fac[n_max]
for i in range(n_max - 1, 1, -1): ifac[i] = ifac[i + 1] * (i + 1)
def main():
h,w,a,b=MI()
cc=[]
for i in range(h-a):
cc.append(nCr(b+i,i))
#print(*cc)
ans=mint(0)
pc=0
for i,c in enumerate(cc):
ans+=(c-pc)*nCr(h-1-i+w-1-b,w-1-b)
pc=c
print(ans)
main()
| 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
s399167431 | p04046 | Runtime Error | import math
# Function to find modulo inverse of b. It returns
# -1 when inverse doesn't
# modInverse works for prime m
def modInverse(b,m):
g = math.gcd(b, m)
if (g != 1):
# print("Inverse doesn't exist")
return -1
else:
# If b and m are relatively prime,
# then modulo inverse is b^(m-2) mode m
return pow(b, m - 2, m)
# Function to compute a/b under modulo m
def modDivide(a,b,m):
a = a % m
inv = modInverse(b,m)
if(inv == -1):
print("Division not defined")
else:
return (inv*a) % m
MOD = (10 ** 9) + 7
H, W, A, B = list(map(int, input().split(' ')))
DP = []
j = 1
for i in range(1,200002):
j *= i
j %= MOD
DP.append(j)
# print(DP)
def factorial(i):
if (i == 0):
return 1
global DP
# print(i)
# print(i, DP[i-1])
# print(DP[i-1])
return DP[i-1]
def move2(H, W, A, B):
numPaths = 0
h = H-A
w = W-(W-B)+1
a = A+1
pttp = 0
for b in range(w, W+1):
# print(h, b, a, W-b+1)
ttp = (factorial(h+b-2)*modInverse((factorial(h-1)*factorial(b-1))% MOD, MOD)) % MOD
tpttp = ttp
ttp -= pttp
pttp = tpttp
btp = (factorial(a+(W-b+1)-2)*modInverse((factorial(a-1)*factorial(W-b))% MOD, MOD)) % MOD
# btp = factorial(a+(W-b+1)-2)//(factorial(a-1)*factorial(W-b))
numPaths += ttp*btp
return numPaths
ways = move2(H, W, A, B)
print(ways % (10**9 + 7)) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.</p>
<p>However, she cannot enter the cells in the intersection of the bottom <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> forbidden cells.) There is no restriction on entering the other cells.</p>
<p>Find the number of ways she can travel to the bottom-right cell.</p>
<p>Since this number can be extremely large, print the number modulo <var>10^9+7</var>.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ H, W ≦ 100,000</var></li>
<li><var> 1 ≦ A < H</var></li>
<li><var> 1 ≦ B < W</var></li>
</ul>
</section>
</div>
<hr/>
<div class="io-style">
<div class="part">
<section>
<h3>Input</h3><p>The input is given from Standard Input in the following format:</p>
<pre><var>H</var> <var>W</var> <var>A</var> <var>B</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the number of ways she can travel to the bottom-right cell, modulo <var>10^9+7</var>.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>2 3 1 1
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2
</pre>
<p>We have a <var>2×3</var> grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>10 7 3 4
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>3570
</pre>
<p>There are <var>12</var> forbidden cells.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 3</h3><pre>100000 100000 99999 99999
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 3</h3><pre>1
</pre>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 4</h3><pre>100000 100000 44444 55555
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 4</h3><pre>738162020
</pre></section>
</div>
</span> |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.