submission_id string | problem_id string | status string | code string | input string | output string | problem_description string |
|---|---|---|---|---|---|---|
s148335538 | p04045 | Runtime Error | N, K = map(int, input().split())
D = list(map(int, input().split()))
shiharai=N
l = [int(x) for x in list(str(N))]
for i in range(l):
while l[i] in D:
shiharai+=1
l = [int(x) for x in list(str(shiharai))]
print(shiharai) | 1000 8
1 3 4 5 6 7 8 9
| 2000
| <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Iroha is very particular about numbers. There are <var>K</var> digits that she dislikes: <var>D_1, D_2, ..., D_K</var>.</p>
<p>She is shopping, and now paying at the cashier.
Her total is <var>N</var> yen (the currency of Japan), thus she has to hand at least <var>N</var> yen to the cashier (and possibly receive the change).</p>
<p>However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.</p>
<p>Find the amount of money that she will hand to the cashier.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ N < 10000</var></li>
<li><var> 1 ≦ K < 10</var></li>
<li><var> 0 ≦ D_1 < D_2 < … < D_K≦9</var></li>
<li><var>\{D_1,D_2,...,D_K\} ≠ \{1,2,3,4,5,6,7,8,9\}</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>N</var> <var>K</var>
<var>D_1</var> <var>D_2</var> … <var>D_K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the amount of money that Iroha will hand to the cashier.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1000 8
1 3 4 5 6 7 8 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2000
</pre>
<p>She dislikes all digits except <var>0</var> and <var>2</var>.</p>
<p>The smallest integer equal to or greater than <var>N=1000</var> whose decimal notation contains only <var>0</var> and <var>2</var>, is <var>2000</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9999 1
0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>9999
</pre></section>
</div>
</span> |
s867128631 | p04045 | Runtime Error |
input_array = list(map(int,input().split()))
N = input_array[0]
input_array = list(map(int,input().split()))
num = [1,1,1,1,1,1,1,1,1,1]
ok = []
out = []
for l in range(len(input_array)):
num[input_array[l]] = 0
for i in range(len(num)):
if num[i] == 1:
ok.append(i)
N = list(str(N))
for n in N:
for m in ok:
if m >= int(n):
out.append(m)
break
for i in range(len(out)-1):
print(out[i],end="")
print(out[-1]) | 1000 8
1 3 4 5 6 7 8 9
| 2000
| <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Iroha is very particular about numbers. There are <var>K</var> digits that she dislikes: <var>D_1, D_2, ..., D_K</var>.</p>
<p>She is shopping, and now paying at the cashier.
Her total is <var>N</var> yen (the currency of Japan), thus she has to hand at least <var>N</var> yen to the cashier (and possibly receive the change).</p>
<p>However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.</p>
<p>Find the amount of money that she will hand to the cashier.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ N < 10000</var></li>
<li><var> 1 ≦ K < 10</var></li>
<li><var> 0 ≦ D_1 < D_2 < … < D_K≦9</var></li>
<li><var>\{D_1,D_2,...,D_K\} ≠ \{1,2,3,4,5,6,7,8,9\}</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>N</var> <var>K</var>
<var>D_1</var> <var>D_2</var> … <var>D_K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the amount of money that Iroha will hand to the cashier.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1000 8
1 3 4 5 6 7 8 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2000
</pre>
<p>She dislikes all digits except <var>0</var> and <var>2</var>.</p>
<p>The smallest integer equal to or greater than <var>N=1000</var> whose decimal notation contains only <var>0</var> and <var>2</var>, is <var>2000</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9999 1
0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>9999
</pre></section>
</div>
</span> |
s119533351 | p04045 | Runtime Error | li_1 = list(map(int,input().split()))
N = li_1[0]
K = li_1[1]
D = list(map(int,input().split()))
minvalue=N
temp=0
for i in range(10*N):
i=i+N
numtemp=i
num_4=int(i/10000)
i=i-10000*num_4
num_3=int(i/1000)
i=i-1000*num_3
num_2=int(i/100)
i=i-100*num_2
num_1=int(i/10)
i=i-10*num_1
num_0=i
for j in range(K):
if (num_0!=D[j])and(num_1!=D[j])and(num_2!=D[j])and(num_3!=D[j])and(num_4!=D[j]):
temp+=1
if temp==K:
num=numtemp
break
temp=0
print(num)
| 1000 8
1 3 4 5 6 7 8 9
| 2000
| <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Iroha is very particular about numbers. There are <var>K</var> digits that she dislikes: <var>D_1, D_2, ..., D_K</var>.</p>
<p>She is shopping, and now paying at the cashier.
Her total is <var>N</var> yen (the currency of Japan), thus she has to hand at least <var>N</var> yen to the cashier (and possibly receive the change).</p>
<p>However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.</p>
<p>Find the amount of money that she will hand to the cashier.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ N < 10000</var></li>
<li><var> 1 ≦ K < 10</var></li>
<li><var> 0 ≦ D_1 < D_2 < … < D_K≦9</var></li>
<li><var>\{D_1,D_2,...,D_K\} ≠ \{1,2,3,4,5,6,7,8,9\}</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>N</var> <var>K</var>
<var>D_1</var> <var>D_2</var> … <var>D_K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the amount of money that Iroha will hand to the cashier.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1000 8
1 3 4 5 6 7 8 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2000
</pre>
<p>She dislikes all digits except <var>0</var> and <var>2</var>.</p>
<p>The smallest integer equal to or greater than <var>N=1000</var> whose decimal notation contains only <var>0</var> and <var>2</var>, is <var>2000</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9999 1
0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>9999
</pre></section>
</div>
</span> |
s074228576 | p04045 | Runtime Error | li_1 = list(map(int,input().split()))
N = li_1[0]
K = li_1[1]
D = list(map(int,input().split()))
minvalue=N
temp=0
for i in range(10*(N+1)):
i=i+N
numtemp=i
num_4=int(i/10000)
i=i-10000*num_4
num_3=int(i/1000)
i=i-1000*num_3
num_2=int(i/100)
i=i-100*num_2
num_1=int(i/10)
i=i-10*num_1
num_0=i
for j in range(K):
if (num_0!=D[j])and(num_1!=D[j])and(num_2!=D[j])and(num_3!=D[j]):
if j==K-1:
temp=1
else:
break
if temp==1:
num=numtemp
break
print(num)
| 1000 8
1 3 4 5 6 7 8 9
| 2000
| <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Iroha is very particular about numbers. There are <var>K</var> digits that she dislikes: <var>D_1, D_2, ..., D_K</var>.</p>
<p>She is shopping, and now paying at the cashier.
Her total is <var>N</var> yen (the currency of Japan), thus she has to hand at least <var>N</var> yen to the cashier (and possibly receive the change).</p>
<p>However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.</p>
<p>Find the amount of money that she will hand to the cashier.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ N < 10000</var></li>
<li><var> 1 ≦ K < 10</var></li>
<li><var> 0 ≦ D_1 < D_2 < … < D_K≦9</var></li>
<li><var>\{D_1,D_2,...,D_K\} ≠ \{1,2,3,4,5,6,7,8,9\}</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>N</var> <var>K</var>
<var>D_1</var> <var>D_2</var> … <var>D_K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the amount of money that Iroha will hand to the cashier.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1000 8
1 3 4 5 6 7 8 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2000
</pre>
<p>She dislikes all digits except <var>0</var> and <var>2</var>.</p>
<p>The smallest integer equal to or greater than <var>N=1000</var> whose decimal notation contains only <var>0</var> and <var>2</var>, is <var>2000</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9999 1
0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>9999
</pre></section>
</div>
</span> |
s511504712 | p04045 | Runtime Error |
li_1 = list(map(int,input().split()))
N = li_1[0]
K = li_1[1]
D = list(map(int,input().split()))
minvalue=N
temp=0
for i in range(N+1):
i=i+N
numtemp=i
num_4=int(i/10000)
i=i-10000*num_4
num_3=int(i/1000)
i=i-1000*num_3
num_2=int(i/100)
i=i-100*num_2
num_1=int(i/10)
i=i-10*num_1
num_0=i
for j in range(K):
if (num_0!=D[j])and(num_1!=D[j])and(num_2!=D[j])and(num_3!=D[j]):
if j==K-1:
temp=1
else:
break
if temp==1:
num=numtemp
break
print(num)
| 1000 8
1 3 4 5 6 7 8 9
| 2000
| <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Iroha is very particular about numbers. There are <var>K</var> digits that she dislikes: <var>D_1, D_2, ..., D_K</var>.</p>
<p>She is shopping, and now paying at the cashier.
Her total is <var>N</var> yen (the currency of Japan), thus she has to hand at least <var>N</var> yen to the cashier (and possibly receive the change).</p>
<p>However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.</p>
<p>Find the amount of money that she will hand to the cashier.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ N < 10000</var></li>
<li><var> 1 ≦ K < 10</var></li>
<li><var> 0 ≦ D_1 < D_2 < … < D_K≦9</var></li>
<li><var>\{D_1,D_2,...,D_K\} ≠ \{1,2,3,4,5,6,7,8,9\}</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>N</var> <var>K</var>
<var>D_1</var> <var>D_2</var> … <var>D_K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the amount of money that Iroha will hand to the cashier.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1000 8
1 3 4 5 6 7 8 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2000
</pre>
<p>She dislikes all digits except <var>0</var> and <var>2</var>.</p>
<p>The smallest integer equal to or greater than <var>N=1000</var> whose decimal notation contains only <var>0</var> and <var>2</var>, is <var>2000</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9999 1
0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>9999
</pre></section>
</div>
</span> |
s342694197 | p04045 | Runtime Error | n,k=map(int,input().split())
d=list(input().split())
for i in range(n,100001):
set_i=set(list(str(i)))
for j in set_i:
if s in d:
break
else:
print(i)
break
| 1000 8
1 3 4 5 6 7 8 9
| 2000
| <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Iroha is very particular about numbers. There are <var>K</var> digits that she dislikes: <var>D_1, D_2, ..., D_K</var>.</p>
<p>She is shopping, and now paying at the cashier.
Her total is <var>N</var> yen (the currency of Japan), thus she has to hand at least <var>N</var> yen to the cashier (and possibly receive the change).</p>
<p>However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.</p>
<p>Find the amount of money that she will hand to the cashier.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ N < 10000</var></li>
<li><var> 1 ≦ K < 10</var></li>
<li><var> 0 ≦ D_1 < D_2 < … < D_K≦9</var></li>
<li><var>\{D_1,D_2,...,D_K\} ≠ \{1,2,3,4,5,6,7,8,9\}</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>N</var> <var>K</var>
<var>D_1</var> <var>D_2</var> … <var>D_K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the amount of money that Iroha will hand to the cashier.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1000 8
1 3 4 5 6 7 8 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2000
</pre>
<p>She dislikes all digits except <var>0</var> and <var>2</var>.</p>
<p>The smallest integer equal to or greater than <var>N=1000</var> whose decimal notation contains only <var>0</var> and <var>2</var>, is <var>2000</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9999 1
0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>9999
</pre></section>
</div>
</span> |
s979709031 | p04045 | Runtime Error | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""042-c"""
import sys
ZERO_UNICODE = 48
def solve(dislike_digits_table, first_like_digit, number):
"""Solve."""
if dislike_digits_table[int(number[0])]:
while dislike_digits_table[int(number[0])]:
number = "{0}{1}".format(chr(ord(number[0]) + 1), number[1:])
number = number.replace(number[1:], first_like_digit * (len(number) - 1))
return number
def main():
"""Main function."""
dislike_digits_table = [False for _ in range(10)]
N, _ = sys.stdin.readline().split(' ')
digits = map(int, sys.stdin.readline().split(' '))
for digit in digits:
dislike_digits_table[digit] = True
first_like_digit = str(next(i for i, v
in enumerate(dislike_digits_table)
if not v))
for i, d in enumerate(N):
if dislike_digits_table[int(d)]:
N = N.replace(N[i:], solve(dislike_digits_table, first_like_digit, N[i:]))
break
print(N)
if __name__ == '__main__':
sys.exit(main()) | 1000 8
1 3 4 5 6 7 8 9
| 2000
| <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Iroha is very particular about numbers. There are <var>K</var> digits that she dislikes: <var>D_1, D_2, ..., D_K</var>.</p>
<p>She is shopping, and now paying at the cashier.
Her total is <var>N</var> yen (the currency of Japan), thus she has to hand at least <var>N</var> yen to the cashier (and possibly receive the change).</p>
<p>However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.</p>
<p>Find the amount of money that she will hand to the cashier.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ N < 10000</var></li>
<li><var> 1 ≦ K < 10</var></li>
<li><var> 0 ≦ D_1 < D_2 < … < D_K≦9</var></li>
<li><var>\{D_1,D_2,...,D_K\} ≠ \{1,2,3,4,5,6,7,8,9\}</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>N</var> <var>K</var>
<var>D_1</var> <var>D_2</var> … <var>D_K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the amount of money that Iroha will hand to the cashier.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1000 8
1 3 4 5 6 7 8 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2000
</pre>
<p>She dislikes all digits except <var>0</var> and <var>2</var>.</p>
<p>The smallest integer equal to or greater than <var>N=1000</var> whose decimal notation contains only <var>0</var> and <var>2</var>, is <var>2000</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9999 1
0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>9999
</pre></section>
</div>
</span> |
s994011015 | p04045 | Runtime Error | N, K = map(int, input().split())
D = list(map(int, input().split()))
L = [i for i in range(10) if i not in D]
A = []
for i in L:
A.append(i)
for i in L:
for j in L:
A.append(10*i+j)
for i in L:
for j in L:
for k in L:
A.append(100*i+10*j+k)
for i in L:
for j in L:
for k in L:
for l in L:
A.append(1000*i+100*j+10*k+l)
for i in L:
for j in L:
for k in L:
for l in L:
for m in L:
A.append(10000*i+1000*j+100*k+10*l+m)
for i in A:
if i >= N:
print(i)
break | 1000 8
1 3 4 5 6 7 8 9
| 2000
| <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Iroha is very particular about numbers. There are <var>K</var> digits that she dislikes: <var>D_1, D_2, ..., D_K</var>.</p>
<p>She is shopping, and now paying at the cashier.
Her total is <var>N</var> yen (the currency of Japan), thus she has to hand at least <var>N</var> yen to the cashier (and possibly receive the change).</p>
<p>However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.</p>
<p>Find the amount of money that she will hand to the cashier.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ N < 10000</var></li>
<li><var> 1 ≦ K < 10</var></li>
<li><var> 0 ≦ D_1 < D_2 < … < D_K≦9</var></li>
<li><var>\{D_1,D_2,...,D_K\} ≠ \{1,2,3,4,5,6,7,8,9\}</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>N</var> <var>K</var>
<var>D_1</var> <var>D_2</var> … <var>D_K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the amount of money that Iroha will hand to the cashier.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1000 8
1 3 4 5 6 7 8 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2000
</pre>
<p>She dislikes all digits except <var>0</var> and <var>2</var>.</p>
<p>The smallest integer equal to or greater than <var>N=1000</var> whose decimal notation contains only <var>0</var> and <var>2</var>, is <var>2000</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9999 1
0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>9999
</pre></section>
</div>
</span> |
s565426486 | p04045 | Runtime Error | n, k = map(int, input().split())
dislikes = list(map(int, input().split())
m = n
while True:
m = list(str(m))
l = []
for p in m:
if int(p) not in dislikes:
l.append(p)
continue
else:
m = int(''.join(m))+1
break
if len(l) >= len(str(n)):
if int(''.join(l))>=n:
break
print(''.join(m)) | 1000 8
1 3 4 5 6 7 8 9
| 2000
| <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Iroha is very particular about numbers. There are <var>K</var> digits that she dislikes: <var>D_1, D_2, ..., D_K</var>.</p>
<p>She is shopping, and now paying at the cashier.
Her total is <var>N</var> yen (the currency of Japan), thus she has to hand at least <var>N</var> yen to the cashier (and possibly receive the change).</p>
<p>However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.</p>
<p>Find the amount of money that she will hand to the cashier.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ N < 10000</var></li>
<li><var> 1 ≦ K < 10</var></li>
<li><var> 0 ≦ D_1 < D_2 < … < D_K≦9</var></li>
<li><var>\{D_1,D_2,...,D_K\} ≠ \{1,2,3,4,5,6,7,8,9\}</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>N</var> <var>K</var>
<var>D_1</var> <var>D_2</var> … <var>D_K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the amount of money that Iroha will hand to the cashier.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1000 8
1 3 4 5 6 7 8 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2000
</pre>
<p>She dislikes all digits except <var>0</var> and <var>2</var>.</p>
<p>The smallest integer equal to or greater than <var>N=1000</var> whose decimal notation contains only <var>0</var> and <var>2</var>, is <var>2000</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9999 1
0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>9999
</pre></section>
</div>
</span> |
s231547753 | p04045 | Runtime Error | N, K = [int(i) for i in input().split()]
ds = [int(i) for i in input().split()]
#N, K = (99999, 8)
#ds = [0,1,2,3,4,5,6,7,9]
def run_code(N, K, ds):
dislike_digits_set = set(i for i in ds)
avail_digits = [i for i in range(10) if i not in dislike_digits_set]
avail_min = avail_digits[0]
def get_next_digit(d):
last = 10
for ad in (avail_digits + [last]):
if ad >= d:
if ad == last:
return (1, avail_min)
else:
return (0, ad)
def to_num(n_digits):
num = 0
n = len(n_digits)
for i in range(n):
num += n_digits[i] * 10**(n-i-1)
return num
def to_digits(num):
return [int(i) for i in str(num)]
def search_nearest_larger(num):
n_digits = to_digits(num)
n = len(n_digits)
for i in range(n):
d_in = n_digits[i]
inc, d_out = get_next_digit(d_in)
if inc == 0 and d_in == d_out:
continue
if inc > 0:
num += 10**(n-i)
return search_nearest_larger(num)
else:
n_digits[i] = d_out
return to_num(n_digits[:i+1] + [avail_min]*(n-i-1))
return to_num(n_digits)
return search_nearest_larger(N)
res = run_code(N, K, ds)
print(res)
| 1000 8
1 3 4 5 6 7 8 9
| 2000
| <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Iroha is very particular about numbers. There are <var>K</var> digits that she dislikes: <var>D_1, D_2, ..., D_K</var>.</p>
<p>She is shopping, and now paying at the cashier.
Her total is <var>N</var> yen (the currency of Japan), thus she has to hand at least <var>N</var> yen to the cashier (and possibly receive the change).</p>
<p>However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.</p>
<p>Find the amount of money that she will hand to the cashier.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ N < 10000</var></li>
<li><var> 1 ≦ K < 10</var></li>
<li><var> 0 ≦ D_1 < D_2 < … < D_K≦9</var></li>
<li><var>\{D_1,D_2,...,D_K\} ≠ \{1,2,3,4,5,6,7,8,9\}</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>N</var> <var>K</var>
<var>D_1</var> <var>D_2</var> … <var>D_K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the amount of money that Iroha will hand to the cashier.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1000 8
1 3 4 5 6 7 8 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2000
</pre>
<p>She dislikes all digits except <var>0</var> and <var>2</var>.</p>
<p>The smallest integer equal to or greater than <var>N=1000</var> whose decimal notation contains only <var>0</var> and <var>2</var>, is <var>2000</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9999 1
0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>9999
</pre></section>
</div>
</span> |
s219891551 | p04045 | Runtime Error | N, K = [int(i) for i in input().split()]
ds = [int(i) for i in input().split()]
#N, K = (99999, 1)
#ds = [0]
def run_code(N, K, ds):
dislike_digits_set = set(i for i in ds)
avail_digits = [i for i in range(10) if i not in dislike_digits_set]
avail_min = avail_digits[0]
def get_next_digit(d):
last = [10]
for ad in (avail_digits + last):
if ad >= d:
if ad == last:
return (1, avail_min)
else:
return (0, ad)
def to_num(n_digits):
num = 0
n = len(n_digits)
for i in range(n):
num += n_digits[i] * 10**(n-i-1)
return num
def to_digits(num):
return [int(i) for i in str(num)]
def search_nearest_larger(num):
n_digits = to_digits(num)
n = len(n_digits)
for i in range(n):
d_in = n_digits[i]
inc, d_out = get_next_digit(d_in)
if inc == 0 and d_in == d_out:
continue
if inc > 0:
| 1000 8
1 3 4 5 6 7 8 9
| 2000
| <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Iroha is very particular about numbers. There are <var>K</var> digits that she dislikes: <var>D_1, D_2, ..., D_K</var>.</p>
<p>She is shopping, and now paying at the cashier.
Her total is <var>N</var> yen (the currency of Japan), thus she has to hand at least <var>N</var> yen to the cashier (and possibly receive the change).</p>
<p>However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.</p>
<p>Find the amount of money that she will hand to the cashier.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ N < 10000</var></li>
<li><var> 1 ≦ K < 10</var></li>
<li><var> 0 ≦ D_1 < D_2 < … < D_K≦9</var></li>
<li><var>\{D_1,D_2,...,D_K\} ≠ \{1,2,3,4,5,6,7,8,9\}</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>N</var> <var>K</var>
<var>D_1</var> <var>D_2</var> … <var>D_K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the amount of money that Iroha will hand to the cashier.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1000 8
1 3 4 5 6 7 8 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2000
</pre>
<p>She dislikes all digits except <var>0</var> and <var>2</var>.</p>
<p>The smallest integer equal to or greater than <var>N=1000</var> whose decimal notation contains only <var>0</var> and <var>2</var>, is <var>2000</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9999 1
0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>9999
</pre></section>
</div>
</span> |
s837836376 | p04045 | Runtime Error | N, K = map(int, input().split())
D = list(map(int, input().split()))
n = str(N)
ans = N
for i in reversed(range(str(len(N)))):
temp = n[i]
while(int(temp) in D):
ans += 1
print(ans)
| 1000 8
1 3 4 5 6 7 8 9
| 2000
| <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Iroha is very particular about numbers. There are <var>K</var> digits that she dislikes: <var>D_1, D_2, ..., D_K</var>.</p>
<p>She is shopping, and now paying at the cashier.
Her total is <var>N</var> yen (the currency of Japan), thus she has to hand at least <var>N</var> yen to the cashier (and possibly receive the change).</p>
<p>However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.</p>
<p>Find the amount of money that she will hand to the cashier.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ N < 10000</var></li>
<li><var> 1 ≦ K < 10</var></li>
<li><var> 0 ≦ D_1 < D_2 < … < D_K≦9</var></li>
<li><var>\{D_1,D_2,...,D_K\} ≠ \{1,2,3,4,5,6,7,8,9\}</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>N</var> <var>K</var>
<var>D_1</var> <var>D_2</var> … <var>D_K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the amount of money that Iroha will hand to the cashier.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1000 8
1 3 4 5 6 7 8 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2000
</pre>
<p>She dislikes all digits except <var>0</var> and <var>2</var>.</p>
<p>The smallest integer equal to or greater than <var>N=1000</var> whose decimal notation contains only <var>0</var> and <var>2</var>, is <var>2000</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9999 1
0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>9999
</pre></section>
</div>
</span> |
s762676909 | p04045 | Runtime Error | N, K = map(int, input().split())
D = list(map(int, input().split()))
n = str(N)
ans = N
for i in reversed(range(N)):
temp = n[i]
while(int(temp) in D):
ans += 1
print(ans)
| 1000 8
1 3 4 5 6 7 8 9
| 2000
| <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Iroha is very particular about numbers. There are <var>K</var> digits that she dislikes: <var>D_1, D_2, ..., D_K</var>.</p>
<p>She is shopping, and now paying at the cashier.
Her total is <var>N</var> yen (the currency of Japan), thus she has to hand at least <var>N</var> yen to the cashier (and possibly receive the change).</p>
<p>However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.</p>
<p>Find the amount of money that she will hand to the cashier.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ N < 10000</var></li>
<li><var> 1 ≦ K < 10</var></li>
<li><var> 0 ≦ D_1 < D_2 < … < D_K≦9</var></li>
<li><var>\{D_1,D_2,...,D_K\} ≠ \{1,2,3,4,5,6,7,8,9\}</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>N</var> <var>K</var>
<var>D_1</var> <var>D_2</var> … <var>D_K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the amount of money that Iroha will hand to the cashier.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1000 8
1 3 4 5 6 7 8 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2000
</pre>
<p>She dislikes all digits except <var>0</var> and <var>2</var>.</p>
<p>The smallest integer equal to or greater than <var>N=1000</var> whose decimal notation contains only <var>0</var> and <var>2</var>, is <var>2000</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9999 1
0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>9999
</pre></section>
</div>
</span> |
s815140573 | p04045 | Runtime Error | n, k = [int(i) for i in input().split()]
q = n
not_liked = [int(i) for i in input().split()]
liked = [i for i in range(10) if i not in not_liked]
digits = list()
while(n):
digits.append(n%10)
n //= 10
digits.reverse()
ind = -2
for i in digits:
if i not in liked:
ind = digits.index(i)
break
js = list()
jss = list()
for i in digits:
for j in liked:
if j >= i:
js.append(j)
jss.append(js[:])
js.clear()
m = 0
number = str()
flag = True
for i in range(len(digits)):
if m != ind+1:
number += str(min(jss[i]))
m += 1
else:
k = len(str(q)) - m
val = int(number + str(min(liked))*k)
if val <= 10000:
print(val)
else:
print(10000)
flag = False
break
if flag:
val1 = int(number)
if val1 <= 10000:
print(val1)
else:
print(10000) | 1000 8
1 3 4 5 6 7 8 9
| 2000
| <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Iroha is very particular about numbers. There are <var>K</var> digits that she dislikes: <var>D_1, D_2, ..., D_K</var>.</p>
<p>She is shopping, and now paying at the cashier.
Her total is <var>N</var> yen (the currency of Japan), thus she has to hand at least <var>N</var> yen to the cashier (and possibly receive the change).</p>
<p>However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.</p>
<p>Find the amount of money that she will hand to the cashier.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ N < 10000</var></li>
<li><var> 1 ≦ K < 10</var></li>
<li><var> 0 ≦ D_1 < D_2 < … < D_K≦9</var></li>
<li><var>\{D_1,D_2,...,D_K\} ≠ \{1,2,3,4,5,6,7,8,9\}</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>N</var> <var>K</var>
<var>D_1</var> <var>D_2</var> … <var>D_K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the amount of money that Iroha will hand to the cashier.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1000 8
1 3 4 5 6 7 8 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2000
</pre>
<p>She dislikes all digits except <var>0</var> and <var>2</var>.</p>
<p>The smallest integer equal to or greater than <var>N=1000</var> whose decimal notation contains only <var>0</var> and <var>2</var>, is <var>2000</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9999 1
0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>9999
</pre></section>
</div>
</span> |
s806999533 | p04045 | Runtime Error | n, k = [int(i) for i in input().split()]
q = n
not_liked = [int(i) for i in input().split()]
liked = [i for i in range(10) if i not in not_liked]
digits = list()
while(n):
digits.append(n%10)
n //= 10
digits.reverse()
ind = -2
for i in digits:
if i not in liked:
ind = digits.index(i)
break
js = list()
jss = list()
for i in digits:
for j in liked:
if j >= i:
js.append(j)
jss.append(js[:])
js = []
m = 0
number = str()
flag = True
for i in jss:
if m != ind+1:
number += str(min(i))
m += 1
else:
k = len(str(q)) - m
val = int(number + str(min(liked))*k)
if val <= 10000:
print(val)
else:
print(10000)
flag = False
break
if flag:
val1 = int(number)
if val1 <= 10000:
print(val1)
else:
print(10000) | 1000 8
1 3 4 5 6 7 8 9
| 2000
| <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Iroha is very particular about numbers. There are <var>K</var> digits that she dislikes: <var>D_1, D_2, ..., D_K</var>.</p>
<p>She is shopping, and now paying at the cashier.
Her total is <var>N</var> yen (the currency of Japan), thus she has to hand at least <var>N</var> yen to the cashier (and possibly receive the change).</p>
<p>However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.</p>
<p>Find the amount of money that she will hand to the cashier.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ N < 10000</var></li>
<li><var> 1 ≦ K < 10</var></li>
<li><var> 0 ≦ D_1 < D_2 < … < D_K≦9</var></li>
<li><var>\{D_1,D_2,...,D_K\} ≠ \{1,2,3,4,5,6,7,8,9\}</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>N</var> <var>K</var>
<var>D_1</var> <var>D_2</var> … <var>D_K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the amount of money that Iroha will hand to the cashier.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1000 8
1 3 4 5 6 7 8 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2000
</pre>
<p>She dislikes all digits except <var>0</var> and <var>2</var>.</p>
<p>The smallest integer equal to or greater than <var>N=1000</var> whose decimal notation contains only <var>0</var> and <var>2</var>, is <var>2000</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9999 1
0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>9999
</pre></section>
</div>
</span> |
s929331940 | p04045 | Runtime Error | n, k = [int(i) for i in input().strip(" ").split()]
q = n
not_liked = [int(i) for i in input().strip(" ").split()]
liked = [i for i in range(10) if i not in not_liked]
digits = list()
while(n):
digits.append(n%10)
n //= 10
digits.reverse()
ind = -2
for i in digits:
if i not in liked:
ind = digits.index(i)
break
js = list()
jss = list()
for i in digits:
for j in liked:
if j >= i:
js.append(j)
jss.append(js[:])
js = []
m = 0
number = str()
flag = True
for i in jss:
if m != ind+1:
number += str(min(i))
m += 1
else:
k = len(str(q)) - m
val = int(number + str(min(liked))*k)
if val <= 10000:
print(val)
else:
print(10000)
flag = False
break
if flag:
val1 = int(number)
if val1 <= 10000:
print(val1)
else:
print(10000) | 1000 8
1 3 4 5 6 7 8 9
| 2000
| <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Iroha is very particular about numbers. There are <var>K</var> digits that she dislikes: <var>D_1, D_2, ..., D_K</var>.</p>
<p>She is shopping, and now paying at the cashier.
Her total is <var>N</var> yen (the currency of Japan), thus she has to hand at least <var>N</var> yen to the cashier (and possibly receive the change).</p>
<p>However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.</p>
<p>Find the amount of money that she will hand to the cashier.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ N < 10000</var></li>
<li><var> 1 ≦ K < 10</var></li>
<li><var> 0 ≦ D_1 < D_2 < … < D_K≦9</var></li>
<li><var>\{D_1,D_2,...,D_K\} ≠ \{1,2,3,4,5,6,7,8,9\}</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>N</var> <var>K</var>
<var>D_1</var> <var>D_2</var> … <var>D_K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the amount of money that Iroha will hand to the cashier.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1000 8
1 3 4 5 6 7 8 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2000
</pre>
<p>She dislikes all digits except <var>0</var> and <var>2</var>.</p>
<p>The smallest integer equal to or greater than <var>N=1000</var> whose decimal notation contains only <var>0</var> and <var>2</var>, is <var>2000</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9999 1
0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>9999
</pre></section>
</div>
</span> |
s402522954 | p04045 | Runtime Error | n, k = [int(i) for i in input().strip(" ").split()]
q = n
not_liked = [int(i) for i in input().strip(" ").split()]
liked = [i for i in range(10) if i not in not_liked]
digits = list()
while(n):
digits.append(n%10)
n //= 10
digits.reverse()
ind = -2
for i in digits:
if i not in liked:
ind = digits.index(i)
break
js = list()
jss = list()
for i in digits:
for j in liked:
if j >= i:
js.append(j)
jss.append(js[:])
js = []
m = 0
number = str()
flag = True
for i in jss:
if m != ind+1:
number += str(min(i))
m += 1
else:
k = len(str(q)) - m
print(int(number + str(min(liked))*k))
flag = False
break
if flag:
print(int(number)) | 1000 8
1 3 4 5 6 7 8 9
| 2000
| <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Iroha is very particular about numbers. There are <var>K</var> digits that she dislikes: <var>D_1, D_2, ..., D_K</var>.</p>
<p>She is shopping, and now paying at the cashier.
Her total is <var>N</var> yen (the currency of Japan), thus she has to hand at least <var>N</var> yen to the cashier (and possibly receive the change).</p>
<p>However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.</p>
<p>Find the amount of money that she will hand to the cashier.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ N < 10000</var></li>
<li><var> 1 ≦ K < 10</var></li>
<li><var> 0 ≦ D_1 < D_2 < … < D_K≦9</var></li>
<li><var>\{D_1,D_2,...,D_K\} ≠ \{1,2,3,4,5,6,7,8,9\}</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>N</var> <var>K</var>
<var>D_1</var> <var>D_2</var> … <var>D_K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the amount of money that Iroha will hand to the cashier.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1000 8
1 3 4 5 6 7 8 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2000
</pre>
<p>She dislikes all digits except <var>0</var> and <var>2</var>.</p>
<p>The smallest integer equal to or greater than <var>N=1000</var> whose decimal notation contains only <var>0</var> and <var>2</var>, is <var>2000</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9999 1
0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>9999
</pre></section>
</div>
</span> |
s839492722 | p04045 | Runtime Error | N, K = raw_input().split()
D = raw_input().split()
candi = [str(i) for i in xrange(10)]
for d in D:
candi.remove(d)
def decide(i):
if i >= len(N):
return ''
for c in candi:
if N[i] == c:
return c + decide(i+1)
elif N[i] < c:
return c + candi[0] * (len(N) - i - 1)
else:
return (candi[0] if candi[0] != 0 else candi[1]) + decide(i)
print decide(0) | 1000 8
1 3 4 5 6 7 8 9
| 2000
| <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Iroha is very particular about numbers. There are <var>K</var> digits that she dislikes: <var>D_1, D_2, ..., D_K</var>.</p>
<p>She is shopping, and now paying at the cashier.
Her total is <var>N</var> yen (the currency of Japan), thus she has to hand at least <var>N</var> yen to the cashier (and possibly receive the change).</p>
<p>However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.</p>
<p>Find the amount of money that she will hand to the cashier.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ N < 10000</var></li>
<li><var> 1 ≦ K < 10</var></li>
<li><var> 0 ≦ D_1 < D_2 < … < D_K≦9</var></li>
<li><var>\{D_1,D_2,...,D_K\} ≠ \{1,2,3,4,5,6,7,8,9\}</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>N</var> <var>K</var>
<var>D_1</var> <var>D_2</var> … <var>D_K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the amount of money that Iroha will hand to the cashier.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1000 8
1 3 4 5 6 7 8 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2000
</pre>
<p>She dislikes all digits except <var>0</var> and <var>2</var>.</p>
<p>The smallest integer equal to or greater than <var>N=1000</var> whose decimal notation contains only <var>0</var> and <var>2</var>, is <var>2000</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9999 1
0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>9999
</pre></section>
</div>
</span> |
s036894632 | p04045 | Runtime Error | import itertools
if __name__ == "__main__":
line_one = input().split()
line_two = input().split()
use_num = {'0','1','2','3','4','5','6','7','8','9'}.difference(line_two)
all_comb = list(itertools.product(use_num, repeat=len(str(line_one[0]))))
nums = list((map(int,["".join(x) for x in all_comb])))
ans = min([x for x in nums if x >= int(line_one[0])])
print(ans) | 1000 8
1 3 4 5 6 7 8 9
| 2000
| <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Iroha is very particular about numbers. There are <var>K</var> digits that she dislikes: <var>D_1, D_2, ..., D_K</var>.</p>
<p>She is shopping, and now paying at the cashier.
Her total is <var>N</var> yen (the currency of Japan), thus she has to hand at least <var>N</var> yen to the cashier (and possibly receive the change).</p>
<p>However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.</p>
<p>Find the amount of money that she will hand to the cashier.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ N < 10000</var></li>
<li><var> 1 ≦ K < 10</var></li>
<li><var> 0 ≦ D_1 < D_2 < … < D_K≦9</var></li>
<li><var>\{D_1,D_2,...,D_K\} ≠ \{1,2,3,4,5,6,7,8,9\}</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>N</var> <var>K</var>
<var>D_1</var> <var>D_2</var> … <var>D_K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the amount of money that Iroha will hand to the cashier.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1000 8
1 3 4 5 6 7 8 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2000
</pre>
<p>She dislikes all digits except <var>0</var> and <var>2</var>.</p>
<p>The smallest integer equal to or greater than <var>N=1000</var> whose decimal notation contains only <var>0</var> and <var>2</var>, is <var>2000</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9999 1
0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>9999
</pre></section>
</div>
</span> |
s447764636 | p04045 | Runtime Error | #include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <utility>
#include <vector>
int main() {
int n, k, d;
bool is_safe[10] = {};
std::cin >> n >> k;
std::fill(is_safe, is_safe + 10, true);
for (int ki = 0 ; ki < k; ++ki) {
std::cin >> d;
is_safe[d] = false;
}
while (true) {
int r = n;
while (r > 0) {
if (not is_safe[r % 10]) {
goto fail;
}
r /= 10;
}
std::cout << n << std::endl;
return 0;
fail:
++n;
}
} | 1000 8
1 3 4 5 6 7 8 9
| 2000
| <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Iroha is very particular about numbers. There are <var>K</var> digits that she dislikes: <var>D_1, D_2, ..., D_K</var>.</p>
<p>She is shopping, and now paying at the cashier.
Her total is <var>N</var> yen (the currency of Japan), thus she has to hand at least <var>N</var> yen to the cashier (and possibly receive the change).</p>
<p>However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.</p>
<p>Find the amount of money that she will hand to the cashier.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ N < 10000</var></li>
<li><var> 1 ≦ K < 10</var></li>
<li><var> 0 ≦ D_1 < D_2 < … < D_K≦9</var></li>
<li><var>\{D_1,D_2,...,D_K\} ≠ \{1,2,3,4,5,6,7,8,9\}</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>N</var> <var>K</var>
<var>D_1</var> <var>D_2</var> … <var>D_K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the amount of money that Iroha will hand to the cashier.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1000 8
1 3 4 5 6 7 8 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2000
</pre>
<p>She dislikes all digits except <var>0</var> and <var>2</var>.</p>
<p>The smallest integer equal to or greater than <var>N=1000</var> whose decimal notation contains only <var>0</var> and <var>2</var>, is <var>2000</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9999 1
0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>9999
</pre></section>
</div>
</span> |
s006728586 | p04045 | Runtime Error | n, k = map(int, raw_input().split())
d = map(int, raw_input().split())
def use_d(n):
for i in list(str(n)):
if int(i) in d:
return True
else:
return False
while n < 100000:
if use_d(n):
n += 1
else:
print n
sys.exit() | 1000 8
1 3 4 5 6 7 8 9
| 2000
| <span class="lang-en">
<p>Score : <var>300</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>Iroha is very particular about numbers. There are <var>K</var> digits that she dislikes: <var>D_1, D_2, ..., D_K</var>.</p>
<p>She is shopping, and now paying at the cashier.
Her total is <var>N</var> yen (the currency of Japan), thus she has to hand at least <var>N</var> yen to the cashier (and possibly receive the change).</p>
<p>However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.</p>
<p>Find the amount of money that she will hand to the cashier.</p>
</section>
</div>
<div class="part">
<section>
<h3>Constraints</h3><ul>
<li><var> 1 ≦ N < 10000</var></li>
<li><var> 1 ≦ K < 10</var></li>
<li><var> 0 ≦ D_1 < D_2 < … < D_K≦9</var></li>
<li><var>\{D_1,D_2,...,D_K\} ≠ \{1,2,3,4,5,6,7,8,9\}</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>N</var> <var>K</var>
<var>D_1</var> <var>D_2</var> … <var>D_K</var>
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Output</h3><p>Print the amount of money that Iroha will hand to the cashier.</p>
</section>
</div>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 1</h3><pre>1000 8
1 3 4 5 6 7 8 9
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 1</h3><pre>2000
</pre>
<p>She dislikes all digits except <var>0</var> and <var>2</var>.</p>
<p>The smallest integer equal to or greater than <var>N=1000</var> whose decimal notation contains only <var>0</var> and <var>2</var>, is <var>2000</var>.</p>
</section>
</div>
<hr/>
<div class="part">
<section>
<h3>Sample Input 2</h3><pre>9999 1
0
</pre>
</section>
</div>
<div class="part">
<section>
<h3>Sample Output 2</h3><pre>9999
</pre></section>
</div>
</span> |
s225904543 | p04046 | Wrong Answer | MODD = 10**9 + 7
fac=[1]*200001
aaa=1
for i in range(1,200001):
aaa=(aaa*i)%MODD
fac[i]=aaa
import math as m
def perm(x,y,z) -> int:
#print(fac[x]//(fac[y]*fac[z]))
return (fac[x]//(fac[y]*fac[z]))
h,w,a,b= [int(x) for x in input().split()]
A = h-a
B = b-1
C = h-1
D = w-b-1
j=0
k=B
kl = C
jl = D
ans = 0
for i in range(B,B+A):
ans+=perm(i,k,i-k)*perm(kl+jl-(i-k),kl-(i-k),jl)
print(ans%MODD)
| 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
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> |
s495465771 | p04046 | Wrong Answer | H, W, A, B = map(int,input().split())
G = [[0]*W for _ in range(H)]
MOD = 10**9+7
for i in range(W):
G[0][i] = 1
for i in range(H):
G[i][0] = 1
for i in range(H-A, H):
for j in range(B):
G[i][j] = -float('inf')
for i in range(1, H):
for j in range(1, W):
a = max(G[i-1][j], 0)
b = max(G[i][j-1], 0)
G[i][j]+=a+b
G[i][j]%=MOD
print(G[H-1][W-1]) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the 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> |
s573780847 | p04046 | Wrong Answer | H, W, A, B = map(int,input().split())
G = [[0]*W for _ in range(H)]
for i in range(W):
G[0][i] = 1
for i in range(H):
G[i][0] = 1
for i in range(H-A, H):
for j in range(B):
G[i][j] = -float('inf')
for i in range(1, H):
for j in range(1, W):
a = max(G[i-1][j], 0)
b = max(G[i][j-1], 0)
G[i][j]+=a+b
print(G[H-1][W-1]) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the 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> |
s092440387 | p04046 | Wrong Answer | H, W, A, B = map(int, input().split())
from math import factorial
mod = 1000000007
Fact = [1]
compro = 1
for i in range(1,H+W):
compro *= i
compro %= mod
Fact.append(compro)
ans = 0
for i in range(B,W):
ans += Fact[H-A-1+i]/Fact[H-A-1]/Fact[i] * Fact[A-1+W-1-i]/Fact[A-1]/Fact[W-1-i]
ans %= mod
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> |
s006471739 | p04046 | Wrong Answer | H, W, A, B = map(int, input().split())
from math import factorial
mod = 1000000007
Fact = [factorial(x)%mod for x in range(H+W)]
ans = 0
for i in range(B,W):
ans += Fact[H-A-1+i]/Fact[H-A-1]/Fact[i] * Fact[A-1+W-1-i]/Fact[A-1]/Fact[W-1-i]
print(int(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> |
s804059412 | p04046 | Wrong Answer | H, W, A, B = map(int, open(0).read().split())
MOD = 10**9+7
factorials = [1] * (H + W + 1)
inv_factorials = [1] * (H + W + 1)
for i in range(H + W):
factorials[i+1] = factorials[i] * (i + 1) % MOD
inv_factorials = list(map(lambda n: pow(n, MOD - 2, MOD), factorials))
def modcomb(m, n, mod):
return factorials[m] * inv_factorials[n] * inv_factorials[m - n] % MOD
total = modcomb(H + W - 2, W - 1, MOD)
for i in range(B):
total = total - modcomb(H - A - 1 + i, i, MOD) * modcomb(A - 1 + W - 1 - i, W - 1 - i, 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> |
s652561515 | p04046 | Wrong Answer | # -*- coding: utf-8 -*-
from scipy.special import comb
def main():
H, W, A, B = map(int, input().split())
whole = 0
part = 0
H = H - 1
W = W - 1
A = A - 1
B = B - 1
whole = comb((H + W), H, exact=True)
part = comb((A + B), A, exact=True)
ans = whole - part
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> |
s766222763 | p04046 | Wrong Answer | # -*- coding: utf-8 -*-
# D - いろはちゃんとマス目
from scipy.special import comb
H, W, A, B = map(int, input().split())
whole = 0
part = 0
whole = comb((H + W) - 2, H - 1, exact=True)
part = comb((A + B), A, exact=True)
ans = whole - part
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> |
s374575742 | p04046 | Wrong Answer | h,w,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
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
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> |
s790602502 | p04046 | Wrong Answer | h,w,a,b=map(int,input().split())
p=10**9+7
#p=127
def modp_factorial(n):
s=1
for x in range(1,h+1):
s=(s*x) % p
return s
def modp_prod(lst):
s=1
for x in lst:
s=(s*x)%p
return s
def inv(n):
s=1
q=p-2
while q>0:
if q&1:
s=s*n % p
n=n*n % p
q>>=1
return s
l=[1]
f=1
for x in range(1,h+w+1):
f=f*x % p
l.append(f)
invl=[inv(l[-1])]
for n in range(h+w,1,-1):
invl.append((invl[-1]*n) % p)
invl.append(1)
invl.reverse()
s=0
for x in range(1,h-a+1):
s=s+modp_prod([l[x+b-2],invl[x-1],invl[b-1]\
,l[w-b+h-x-1],invl[h-x],invl[w-b-1]])% p
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> |
s657351710 | p04046 | Wrong Answer | from scipy.special import comb
H, W, A, B = map(int, input().split())
ans = 0
for i in range(W - B+1):
ans += comb(H - A + B + i, H-A, exact=True) * \
comb(W - B + A - i, A, exact=True)
ans = int(ans % (10**9+7))
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> |
s642889501 | p04046 | Wrong Answer | from math import factorial
H,W,A,B = map(int,input().split())
rt = 0
for i in range(H-A):
rt += (factorial(i+B-1) * factorial(H-i+W-B-2)) // (factorial(i) * factorial(B-1) * factorial(H-i-1) * factorial(W-B-1))
print(rt % 100000007) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
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> |
s260135513 | p04046 | Wrong Answer | from math import factorial
H,W,A,B = map(int,input().split())
rt = 1
for i in range(H-A-1):
rt += (factorial(i+B) * factorial(H-i+W-B)) // (factorial(i+1) * factorial(B) * factorial(H-i) * factorial(W-B))
print(rt)
print(rt % 100000007) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
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> |
s431428133 | p04046 | Wrong Answer | import sys
import numpy as np
import random
from decimal import Decimal
import itertools
import re
import bisect
from collections import deque, Counter
from functools import lru_cache
sys.setrecursionlimit(10**9)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ')
def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w]
def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w]
MOD = 1000000007
def main():
n = LI()
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> |
s459479103 | p04046 | Wrong Answer | def frac(n):
m=1
for i in range(1, n+1):
m = m * i % 1000000007
return m % 1000000007
(h,w,a,b)=[int(x) for x in input().split()]
ans=0
for i in range(1,w-b+1):
ans+=(((frac(h-a-1+w-i)/(frac(h-a-1)*frac(w-i)))%1000000007)*((frac(a-1+i-1)/(frac(a-1)*frac(i-1)))%1000000007))%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> |
s003447190 | p04046 | Wrong Answer | h,w,a,b=map(int, input().split())
| 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the 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> |
s342887210 | p04046 | Wrong Answer | from math import factorial
h,w,a,b=map(int,input().split())
res=0
fact=[]
for i in range(h+w):
fact.append(factorial(i))
for i in range(b+1,w+1):
first=fact[i+h-a-2]//(fact[i-1]*fact[h-a-1])
second=fact[w-i+a-1]//(fact[w-i]*fact[a-1])
res+=first*second
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> |
s699199104 | p04046 | Wrong Answer | def conbi(n, r):
bunbo = 1
bunshi = 1
if n / 2 < r:
r = n - r
while r > 0:
bunbo *= r
bunshi *= n
r -= 1
n -= 1
return bunshi // bunbo
def conbi_mod(n, r):
return conbi(n, r) % (10 ** 9 + 7)
H, W, A, B = map(int, input().split())
if B < W / 2:
not_ans = 0
total = conbi_mod((H - 1) + (W - 1), H-1)
for i in range(B):
sq1h = H - A
sq1w = i + 1
sq2h = A
sq2w = W - i
n = conbi_mod((sq1h -1) + (sq1w - 1), (sq1h -1)) * conbi_mod((sq2h - 1) + (sq2w - 1), (sq2h - 1))
not_ans += n
ans = total - not_ans
print(ans)
else:
ans = 0
for i in range(B, W):
sq1h = H - A
sq1w = i + 1
sq2h = A
sq2w = W - i
n = conbi_mod((sq1h - 1) + (sq1w - 1), (sq1h - 1)) * conbi_mod((sq2h - 1) + (sq2w - 1), (sq2h - 1))
ans += 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> |
s227611326 | p04046 | Wrong Answer | def conbi(n, r):
bunbo = 1
bunshi = 1
if n / 2 < r:
r = n - r
while r > 0:
bunbo *= r
bunshi *= n
r -= 1
n -= 1
return bunshi // bunbo
def conbi_mod(n, r):
return conbi(n, r) % (10 ** 9 + 7)
H, W, A, B = map(int, input().split())
if B < W / 2:
not_ans = 0
total = conbi_mod((H - 1) + (W - 1), H-1)
for i in range(B):
sq1h = H - A
sq1w = i + 1
sq2h = A
sq2w = W - i
n = conbi((sq1h -1) + (sq1w - 1), (sq1h -1)) * conbi((sq2h - 1) + (sq2w - 1), (sq2h - 1)) % (10 ** 9 + 7)
not_ans += n
ans = total - not_ans
print(ans)
else:
ans = 0
for i in range(B, W):
sq1h = H - A
sq1w = i + 1
sq2h = A
sq2w = W - i
n = conbi((sq1h - 1) + (sq1w - 1), (sq1h - 1)) * conbi((sq2h - 1) + (sq2w - 1), (sq2h - 1)) % (10 ** 9 + 7)
ans += 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> |
s073687667 | p04046 | Wrong Answer | 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> |
s319353649 | p04046 | Wrong Answer | h,w,a,b = map(int,input().split())
MOD = 10**9 + 7
def comb(n,r):
res = 1
fac = 1
for i in range(r):
res *= n-i
res %= MOD
fac *= i+1
fac %= MOD
return res*pow(fac,MOD-2,MOD)%MOD
cnt = 0
for i in range(w-b+1):
cnt += comb(h-a-1+b+i,h-a-1) * comb(w-b-i-1+a-1,a-1)
print(cnt%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> |
s073445048 | p04046 | Wrong Answer | from scipy.misc import comb
h, w, a, b = (int(x) for x in input().split())
ans = 0
for j in range(b, w):
ans += comb(h-a-1 + j, j, exact=True) * comb(a+w-2 - j, w-1 - j, exact=True)
ans %= 100000007
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> |
s737649009 | p04046 | Wrong Answer | import math
def conbination(m, n):
return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))
h, w, a, b = (int(x) for x in input().split())
ans = 0
for j in range(b, w):
ans += conbination(h - a + j - 1, j) * conbination(a + w - j - 2, w - j - 1)
ans %= 100000007
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> |
s683424295 | p04046 | Wrong Answer |
a,b,c,d = list(map(int, input().split()))
def cmb(n, r, p):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n-r] % p
p = 10**9+7
N = 10 ** 6 + 2
fact = [1, 1] # fact[n] = (n! mod p)
factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1] # factinv 計算用
for i in range(2, N + 1):
fact.append((fact[-1] * i) % p)
inv.append((-inv[p % i] * (p // i)) % p)
factinv.append((factinv[-1] * inv[-1]) % p)
def wh(w,h):
return cmb(w+h,w,10**9+7)
ans = wh(b-1,a-1)
print(ans)
for i in range(d):
tmp = wh(i,a-c-1) * wh(c-1,b-i-1) % p
ans += p
ans -= tmp
ans %= p
#print(ans)
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> |
s442574676 | p04046 | Wrong Answer | H, W, A, B = map(int, input().split())
total = 0
tmp1, tmp2 = 1, 1 # 初期化
tmp3, tmp4 = 1, 1 # 初期化
for i in range(B,W,1):
conv1, conv2 = 0, 0 # 初期化
if i == B:
for j in range(i):
tmp1 *= i+(H-A-1)-j
tmp1 %= (10**9+7)
for j in range(i, 0, -1):
tmp2 *= j
tmp2 %= (10**9+7)
else:
tmp1 *= i+(H-A-1)
tmp1 %= (10**9+7)
tmp2 *= i
tmp2 %= (10**9+7)
conv1 = tmp1/tmp2
if i == B:
for j in range(W-1-i):
tmp3 *= (A-1)+(W-1-i)-j
tmp3 %= (10**9+7)
for j in range(W-1-i, 0, -1):
tmp4 *= j
tmp4 %= (10**9+7)
else:
tmp3 *= W-1-i+1
tmp3 %= (10**9+7)
tmp4 *= (A-1)+(W-1-i)+1
tmp4 %= (10**9+7)
conv2 = tmp3/tmp4
total += conv1*conv2
print(int(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> |
s682169581 | p04046 | Wrong Answer | H, W, A, B = map(int, input().split())
# 全組み合わせ数
total = 1
min_num = min(H-1, W-1)
for i in range(min_num):
total *= (H+W-2)-i
total %= (10**9+7)
tmp = 1
for i in range(min_num, 0, -1):
tmp *= i
tmp %= (10**9+7)
total /= tmp
#print(int(total))
# 除外する組み合わせ数
remove_num = 0
if A == 1:
remove_num = 1
else:
if B == 1:
remove_num = A
else:
for i in range(A):
remove_num1 = 1 # 初期化
remove_num2 = 1 # 初期化
if i == 0:
for j in range(H-1):
remove_num1 *= (H-1)+(B-1)-j
remove_num1 %= (10**9+7)
tmp = 1
for j in range(H-1, 0, -1):
tmp *= j
tmp %= (10**9+7)
remove_num1 /= tmp
remove_num += remove_num1
else:
for j in range(H-1-i):
remove_num1 *= (H-1-i)+(B-1)-j
remove_num1 %= (10**9+7)
tmp = 1
for j in range(H-1-i, 0, -1):
tmp *= j
tmp %= (10**9+7)
remove_num1 /= tmp
for j in range(i):
remove_num2 *= i + W-B-1-j
remove_num2 %= (10**9+7)
tmp = 1
for j in range(i, 0, -1):
tmp *= j
tmp %= (10**9+7)
remove_num2 /= tmp
remove_num += remove_num1*remove_num2
print(int(total-remove_num)) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
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> |
s666634370 | p04046 | Wrong Answer | h, w, a, b = map(int, input().split())
def cmb(n, r, mod):
if ( r<0 or r>n ):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
g1.append( ( g1[-1] * i ) % mod )
inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
g2.append( (g2[-1] * inverse[-1]) % mod )
all_comb = cmb(h+w-2, h-1, mod)
for i in range(a):
all_comb=all_comb-(cmb(h+b-i-2, h-i-1, mod)*cmb(w-b-1+i, i, mod))
print(int(all_comb)) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
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> |
s768234672 | p04046 | Wrong Answer | mod = 10 ** 9 + 7
fac_table = [1 for i in range(200001)]
inv_table = [1 for i in range(200001)]
def make_table(h, w):
for i in range(1, h + w - 1):
fac_table[i] = fac_table[i - 1] * i % mod
inv_table[i] = pow(fac_table[i], mod - 2, mod)
def comb(n, r):
return fac_table[n] * inv_table[n - r] % mod * inv_table[r] % mod
def resolve():
H, W, A, B = map(int, input().split())
make_table(H, W)
print(
sum(
[
comb(H - A - 1 + i, i) * comb(A - 1 + W - i - 1, A - 1) % mod
for i in range(B, W)
]
)
% 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> |
s742427691 | p04046 | Wrong Answer | h, w, a, b = map(int, input().split())
f = [[0 for i in range(w)] for j in range(h)]
for i in range(w):
f[0][i] = 1
for i in range(h-a):
f[i][0] = 1
for i in range(1, h):
for j in range(1, w):
if not (i >= h-a and j <= b-1):
f[i][j] = f[i-1][j] + f[i][j-1]
print(f[h-1][w-1]) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the 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> |
s867173209 | p04046 | Wrong Answer | def main():
def cmb(n, r, mod):
if (r < 0 or r > n):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7 # 出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] # 逆元テーブル
inverse = [0, 1] # 逆元テーブル計算用テーブル
for i in range(2, N + 1):
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 = cmb((H+W-2), min(H, W)-1, mod)
tmp = 0
for i in range(B):
t = cmb(H-A-1+i, i, mod)
t *= cmb(W-1-i + A - 1, A-1, mod)
tmp += t
tmp %= mod
print(ans, tmp)
print((ans - tmp) % mod)
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> |
s221157131 | p04046 | Wrong Answer | H,W,A,B = map(int,input().split())
class Combination:
"""
O(n)の前計算を1回行うことで,O(1)でnCr mod mを求められる
n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
使用例:
comb = Combination(1000000)
print(comb(5, 3)) # 10
"""
def __init__(self, n_max, mod=10 ** 9 + 7):
self.mod = mod
self.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(1000000)
ans = 0
for i in range(B,W):
ans += comb(H-A-1+i,i)*comb(A-1+W-1-i,A-1)
#print(comb(H-A-1+i,i)*comb(A-1+W-1-i,A-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> |
s144912752 | p04046 | Wrong Answer | h,w,a,b = map(int,input().split())
dp = [[0 for i in range(h+1)] for j in range(w+1)]
for i in range(w):
for j in range(h):
dp[i+1][j+1] = dp[i][j+1] + dp[i+1][j]
if i == 0 and j == 0:
dp[i+1][j+1] = 1
if i < b and j >= h-a:
dp[i+1][j+1] = 0
print(dp[w][h]) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the 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> |
s882975058 | p04046 | Wrong Answer | from sys import stdin
from operator import itemgetter
import math
# stdin = open("sample.txt")
H,W,A,B = [int(x) for x in stdin.readline().rstrip().split()]
path_list = list(range(W-B))
path_list2 = list(range(0))
path_list.reverse()
for path in path_list:
path_list2.append(math.factorial((W-path-1)+(H-A-1))//math.factorial(W-path-1)//math.factorial(H-A-1))
H2 = A+1
W2 = W-B
path2_list = [[0] * (W2) for i in range(H2)]
h = 0
w = 0
while h < H2:
path2_list[h][0] = path_list2[0]
h += 1
while w < W2:
path2_list[0][w] = path_list2[w]
w += 1
h2 = 1
w2 = 1
ans = 0
while h2 <= H2-1 and w2 <= W2-1:
ans = (path2_list[h2-1][w2] + path2_list[h2][w2-1])
path2_list[h2][w2] = ans
if w2 == W2-1:
h2 += 1
w2 = 1
else:
w2 += 1
print(path2_list[H2-1][W2-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> |
s421388698 | p04046 | Wrong Answer | h,w,a,b = map(int, input().split())
def modinv(a, mod=10**9+7):
return pow(a, mod-2, mod)
def comb(n, r, mod=10**9+7):
r = min(r, n-r)
res = 1
for i in range(r):
res = res * (n - i) * modinv(i+1, mod) % mod
return res
ans=0
for i in range(h-a):
pre=comb(i+b-1,i)
post=comb(h+w-b-2-i,h-i-1)
ans+=pre*post
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> |
s583800768 | p04046 | Wrong Answer | def f(x):
if x==0:
return 1
else:
fac=1
for i in range(1,x+1):
fac*=i
return fac
def c(x,y):
return f(x+y)//(f(x)*f(y))
h,w,a,b=map(int,input().split())
ans=0
ans+=c((h-a-1),(b))*c((a),(w-b-1))
for i in range(h-a-1):
ans+=c(i,b)*c(h-i-1,w-b-2)
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> |
s703950396 | p04046 | Wrong Answer | N=2*10**5+3
mod=10**9+7
fac=[1]*(N+1)
for i in range(1,N+1):
fac[i]=fac[i-1]*i%mod
inv_fac=[1]*(N+1)
inv_fac[N]=pow(fac[N],mod-2,mod)
for i in range(N-1,0,-1):
inv_fac[i]=inv_fac[i+1]*(i+1)%mod
def nCr(n,r):
if n<=0 or r<0 or r>n:
return 0
return fac[n]*inv_fac[r]%mod*inv_fac[n-r]%mod
h,w,a,b=map(int,input().split())
ans=nCr(h+w-2,h-1)
for i in range(b):
ans=(ans-nCr(h-a+i-1,i)*nCr(a+w-i-2,a-1))%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> |
s481182268 | p04046 | Wrong Answer | H, W, A, B = map(int, input().split())
import math
def f(n):
a1 = pow(math.factorial(B + n + H - A - 1), 1, 10**9+7)
a2 = pow(math.factorial(W - B - 1 - n + A - 1), 1, 10**9+7)
b1 = pow(math.factorial(B + n) % (10**9 + 7), 1, 10**9+7)
b2 = pow(math.factorial(H - A - 1) % (10**9 + 7), 1, 10**9+7)
b3 = pow(math.factorial(W - B - 1 - n) % (10**9 + 7), 1, 10**9+7)
b4 = pow(math.factorial(A - 1) % (10**9 + 7), 1, 10**9+7)
return int(a1 * a2 / b1 / b2 / b3 / b4)
def sigma(func, frm, to):
result = 0
for i in range(frm, to+1):
result += func(i)
return result
print(sigma(f, 0, W-B-1)) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the 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> |
s361316546 | p04046 | Wrong Answer | H, W, A, B = map(int, input().split())
import math
def f(n):
a1 = math.factorial(B + n + H - A - 1) % (10**9 + 7)
a2 = math.factorial(W - B - 1 - n + A - 1) % (10**9 + 7)
b1 = math.factorial(B + n) % (10**9 + 7)
b2 = math.factorial(H - A - 1) % (10**9 + 7)
b3 = math.factorial(W - B - 1 - n) % (10**9 + 7)
b4 = math.factorial(A - 1) % (10**9 + 7)
return int(a1 * a2 / b1 / b2 / b3 / b4)
def sigma(func, frm, to):
result = 0
for i in range(frm, to+1):
result += func(i)
return result
print(sigma(f, 0, W-B-1)) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the 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> |
s060932146 | p04046 | Wrong Answer | H, W, A, B = map(int, input().split())
import math
def f(n):
a1 = math.factorial(B + n + H - A - 1) % (10**9 + 7)
a2 = math.factorial(W - B - 1 - n + A - 1) % (10**9 + 7)
b1 = math.factorial(B + n) % (10**9 + 7)
b2 = math.factorial(H - A - 1) % (10**9 + 7)
b3 = math.factorial(W - B - 1 - n) % (10**9 + 7)
b4 = math.factorial(A - 1) % (10**9 + 7)
return a1 * a2 / b1 / b2 / b3 / b4
def sigma(func, frm, to):
result = 0
for i in range(frm, to+1):
result += func(i)
return result
print(sigma(f, 0, W-B-1)) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the 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> |
s770688043 | p04046 | Wrong Answer | h,w,a,b=map(int,input().split())
mod=10**9+7
ans=0
def cmb(n, r, mod):
if ( r<0 or r>n ):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7 #出力の制限
N = h+w+1
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
g1.append( ( g1[-1] * i ) % mod )
inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
g2.append( (g2[-1] * inverse[-1]) % mod )
#a = cmb(n,r,mod)
for i in range(h-a):
p=(i+1)+(b-1)
q=(h-i-1)+((w-b)-1)
ans+=cmb(p,i+1,mod)*cmb(q,h-i-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> |
s406739000 | p04046 | Wrong Answer | from scipy.misc import comb
H,W,A,B=map(int,input().split())
p=0
for i in range(B+1,W+1):
p+=comb(H-A+i,i,exact=True)*comb(W-i+1+A,A,exact=True)
k=p%1000000007
print(k)
| 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the 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> |
s393093312 | p04046 | Wrong Answer | # 0<=y<h-bなるyを通るとこからゴールの右下までのnCrをする
# グリッドじゃなくてマス目にしただけでnCrわからなくなるの、あたまが弱すぎる
h, w, a, b = map(int, input().split())
ans = 0
def ncr(n, r):
res = 1
for i in range(1, r + 1):
res = res * (n - i + 1) // i
return res
print(ncr(h + w, h))
for y in range(1, h - b + 1):
ans += ncr(y, a) * ncr(w - a - 1 + h - b, w - a)
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> |
s989878011 | p04046 | Wrong Answer | import fractions
H,W,A,B=map(int,input().split())
mod =10**9+7
def C(n,m):
if n*m==0:
C =1
else:
bunbo=[0]*min(m,n)
bunsi=[0]*min(m,n)
for k in range(min(m,n)):
bunbo[k]=min(m,n)-k
bunsi[k]=n+m-k
for k in range(min(m,n)):
for j in range(min(n,m)):
if fractions.gcd(bunsi[j],bunbo[k])==0:
gcd =fractions.gcd(bunsi[j],bunbo[k])
bunsi[j]=bunsi[j]//gcd
bunbo[k]=bunbo[k]//gcd
if bunbo[k]==1:
break
C=1
for k in range(min(n,m)):
C=C*bunsi[k]%mod
return C
Total = C(H-1,W-1)
dame = 0
for k in range(B):
dame += C(k,H-A-1)*C(W-1-k,A-1)
answer = (Total-dame)%mod
print(answer) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
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> |
s465912181 | p04046 | Wrong Answer | H,W,A,B=map(int,input().split())
def kumi(h,w,a):
a[0]=1
#print(a)
for i in range(1,h):
a[i]=a[i-1]*(i-1+w)//i%(10**9+7)
#print(a)
return a
f=[0]*(H-A)
s=[0]*(H)
f=kumi(H-A,B,f)
s=kumi(H,W-B,s)
#print(f)
#print(s)
ans=0
for i in range(H-A):
ans+=f[i]*s[-i-1]
print(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> |
s176266581 | p04046 | Wrong Answer | H, W, A, B = map(int,input().split())
MOD = 10**9 + 7
def prepare(n, MOD):
# 1! - n! の計算
f = 1
factorials = [1] # 0!の分
for m in range(1, n + 1):
f *= m
f %= MOD
factorials.append(f)
# n!^-1 の計算
inv = pow(f, MOD - 2, MOD)
# n!^-1 - 1!^-1 の計算
invs = [1] * (n + 1)
invs[n] = inv
for m in range(n, 1, -1):
inv *= m
inv %= MOD
invs[m - 1] = inv
return factorials, invs
#以下、引数にnCrのnに相当する数を入れる。
factorials, invs = prepare(H+W,MOD)
#以下でnCrのMODを求める。
ans = 0
#x = W - B - 1
for b in range(B,W):
#if i == 0:
# ans += (factorials[H-A-1+B] * invs[H-A-1] % MOD * invs[B] % MOD) * (factorials[A+W-B] * invs[A] % MOD * invs[W-B] % MOD) % MOD
#else:
# ans += ((factorials[H-A-1+B+i] * invs[H-A-1] % MOD * invs[B+i] % MOD) - (factorials[H-A-1+B+i-1] * invs[H-A-1] % MOD * invs[B+i-1] % MOD)) * (factorials[A+W-B-i] * invs[A] % MOD * invs[W-B-i] % MOD) % MOD
ans += ((factorials[H-A-1+b] * invs[H-A-1] % MOD * invs[b] % MOD) * (factorials[A-1+W-b-1] * invs[A-1] % MOD * invs[W-b-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> |
s840987147 | p04046 | Wrong Answer | h,w,a,b = map(int, input().split())
mod = 10**9 + 7
n = 10**5 * 2 + 1
fact = [1]*(n+1)
rfact = [1]*(n+1)
r = 1
for i in range(1, n+1):
fact[i] = r = r * i % mod
rfact[n] = r = pow(fact[n], mod-2, mod)
for i in range(n, 0, -1):
rfact[i-1] = r = r * i % mod
# nPk (mod MOD) を求める
def perm(n, k):
return fact[n] * rfact[n-k] % mod
# nCk (mod MOD) を求める
def comb(n, k):
if n == 0 and k == 0:
return 0
return fact[n] * rfact[k] * rfact[n-k] % mod
ans = 0
for i in range(b,w):
ans = (ans + comb(h-a-1+i,i) * comb(w-i+a-2,a-1)) % 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> |
s251441257 | p04046 | Wrong Answer | from array import *
import time
h, w, a, b = map(int, input().split(' '))
MOD = 10**9 + 7
MAX = max(h+w-a-1, a+w)
s = time.time()
def modpow(a, b):
res = 1
while b:
if (b & 1):
res = (res * a) % MOD
a = (a * a) % MOD
b >>= 1
return res
def nCr(n, r):
if r == 0 or n == r:
return 1
return (((f[n] * ivf[n-r]) % MOD) * ivf[r]) % MOD
f = [1] * MAX
f = array('q', f)
ivf = [0] * MAX
ivf = array('q', ivf)
for i in range(1, MAX):
f[i] = (f[i-1] * i) % MOD
ivf[i] = modpow(f[i], MOD-2)
r = 0
for i in range(b, w):
y1 = h - a - 1
x1 = i
y2 = a - 1
x2 = w - i - 1
p = (nCr(x1 + y1, x1) * nCr(x2 + y2, x2)) % MOD
r = (r + p) % MOD
print(int(r))
e = time.time()
print(e - 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> |
s023032841 | p04046 | Wrong Answer | # # import numpy as np
# # import math
# # import sys
# # sys.float_info.max
# # H, W, A, B = map(int, input().split())
# # StoB = np.zeros(B)
# # BtoE = np.zeros(B)
# # sum = 0
# # all = math.factorial(H + W - 2) / (math.factorial(H - 1) * math.factorial(W - 1))
# # all = all % (10 ** 9 + 7)
# # for i in range(B):
# # StoB[i] = math.factorial((i) + (H - A - 1)) / (math.factorial(i) * math.factorial(H - A - 1))
# # BtoE[i] = math.factorial((W - i) + A - 2) / (math.factorial(W - i - 1) * math.factorial(A - 1))
# # sum += StoB[i] * BtoE[i]
# # print(int(all - sum) % (10 ** 9 - 7))
H, W, A, B = map(int, input().split())
mod = 10 ** 9 + 7
#前計算 f[i] = i!
f = [1]
# print(f)
for i in range(H + W):
f.append(f[i] * (i + 1) % mod)
# print(f)
def comb(n, r, p):
print('n = ' + str(n))
print('r = ' + str(r))
# print(f[n])
return f[n] * pow(f[r], p-2, p) * pow(f[n-r], p-2, p) % p
ans = 0
for i in range(W-B+1):
print('i = ' + str(i))
ans += comb(H-A+B+i, H-A, mod) * comb(A+W-B-i, A, mod) % mod
print('ans = ' + str(ans))
print(ans % mod)
# # h,w,a,b = map(int,input().split()) #入力
# mod = 10**9+7
# #前計算 f[i] = i!
# f=[1]
# for i in range(h+w):
# f.append(f[i]*(i+1)%mod)
# #C(n,r,p) = ( n! * r!^(p-2) * (n-r)!^(p-2) )%p
# #pythonだとpow()で二分累乗法が使える
# def comb(n, r, p):
# return f[n] * pow(f[r], p-2, p) * pow(f[n-r], p-2, p) % p
# #紫点ごとに調べる
# ans=0
# for i in range(b, w):
# ans+= comb(h+i-a-1, i, mod) * comb(w-1-i+a-1, a-1, mod) % mod
# print(ans%mod) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the 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> |
s901014310 | p04046 | Wrong Answer | H, W, A, B = map(int, input().split())
mod=10**9+7
N=H+W+1
bikkuri=[0 for i in range(N)]
bikkuri[0]=1
for i in range(1,N):
bikkuri[i] = (i * bikkuri[i-1])%mod
gyaku=[0 for i in range(N)]
gyaku[0]=1
for i in range(1, N):
gyaku[i]=pow(bikkuri[i], mod-2, mod)
def comb(n,r):
return bikkuri[n]*gyaku[n-r]*gyaku[r]%mod
def homb(n,r):
return comb(n+r,r)%mod
dame = []
for i in range(B):
dame.append(homb(H-A-1, i) * homb(W-1-i,A-1))
ans = homb(W-1, H-1) - sum(dame)
| 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
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> |
s359316458 | p04046 | Wrong Answer | H, W, A, B = list(map(int, input().split()))
bikkuri=[1]
mod = 10**9 + 7
for i in range(1, H+W):
bikkuri.append((i * bikkuri[i-1])%mod)
def comb(n, r):
return round(bikkuri[n] / (bikkuri[n-r] * bikkuri[r]))
dame = []
for i in range(B):
dame.append(comb(H-A-1+i, i)%mod * comb(W-1-i+A-1,A-1)%mod)
ans = comb(W-1+H-1, H-1)%mod - sum(dame)
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> |
s632648545 | p04046 | Wrong Answer | def nCr(n, r):
r = min(r, n - r)
if r == 0: return 1;
if r == 1: return n;
numerator = [n - r + i + 1 for i in range(r)]
denominator = [i + 1 for i in range(r)]
for p in range(2, r + 1):
pivot = denominator[p - 1]
if pivot > 1:
offset = (n - r) % p
for k in range(p - 1, r, p):
numerator[k - offset] /= pivot
denominator[k] /= pivot
result = 1
for k in range(r):
if numerator[k] > 1:
result *= numerator[k]
result = result%inf
return int(result)
h, w, a, b = map(int, input().split())
inf = 10**9+7
key1, key2 = 1, nCr(h+w-b-2, h-1)
ans = key2%inf
for i in range(1, h-a):
key = (key1*(b+i)//i)%inf
key2 = (key2*(h-1-i+1)//(h+w-b-2-i+1))%inf
ans = (ans+((key-key1))*key2)%inf
key1 = key
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> |
s916458393 | p04046 | Wrong Answer | h,w,a,b=map(int,input().split())
ans = 0
mod = 10**9 + 7
flist = [1] * (h+w+1)
for i in range(1,h+w):
flist[i] = (flist[i-1] * i)%mod
def cmb(n,r):
return (flist[n]//(flist[r]*flist[n-r]))%mod
for x in range(b,w):
c = x + (h - a - 1)
d = (w - x - 1) + (a - 1)
e = cmb(c, x) * cmb(d, a - 1)
ans = (ans+e)%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> |
s131458036 | p04046 | Wrong Answer | h,w,a,b=map(int,input().split())
ans = 0
mod = 10**9 + 7
flist = [1] * (h+w+1)
for i in range(1,h+w):
flist[i] = (flist[i-1] * i)%mod
def cmb(n,r):
return (flist[n]//(flist[r]*flist[n-r]))%mod
for x in range(b,w):
c = x + (h - a - 1)
d = (w - x - 1) + (a - 1)
e = cmb(c, x) * cmb(d, a - 1)
ans += e
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> |
s173552247 | p04046 | Wrong Answer | h,w,a,b=map(int,input().split())
ans = 0
flist = [1 for _ in range(h+w)]
for i in range(1,h+w):
flist[i] = flist[i-1] * i
def cmb(n,r):
return flist[n]//(flist[r]*flist[n-r])
for x in range(b,w):
c = x + (h - a - 1)
d = (w - x - 1) + (a - 1)
e = cmb(c, x) * cmb(d, a - 1)
ans += e
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> |
s291255669 | p04046 | Wrong Answer | import math
def comb(n, r):
return math.factorial(n) // (math.factorial(r) * math.factorial(n - r))
h, w, a, b = list(map(int, input().split()))
ans = 0
for i in range(w-b):
if (i == 0):
ans += comb(h-a-1+b+i, b+i) * comb(a+w-1-b-i, a)
else:
ans += (comb(h-a-1+b+i, b+i) - comb(h-a-1+b+i-1, b+i-1)) * comb(a+w-1-b-i, a)
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> |
s578227835 | p04046 | Wrong Answer | from operator import mul
from functools import reduce
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
nums = input().split()
H = int(nums[0])
W = int(nums[1])
A = int(nums[2])
B = int(nums[3])
MX = max(H,W)
MN = min(H,W)
mod = 10**9 + 7
#全体
total = cmb(H+W-2,W-1)
#侵入不可
K = 1
forbidden = 0
while K < B + 1:
x1 = cmb(H-A+K-2,K-1)
x2 = cmb(W-K+A-2,A-1)
x = x1 * x2
forbidden += x
x = 0
x1 = 0
x2 = 0
K += 1
answer = int(total - forbidden)
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> |
s338908529 | p04046 | Wrong Answer | def comb(n,k,p):
from math import factorial
if n<0 or k<0 or n<k: return 0
if n==0 or k==0: return 1
a=factorial(n)%p
b=factorial(k)%p
c=factorial(n-k)%p
return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
if b==0: return 1
if b%2==0:
d=power_func(a,b//2,p)
return d*d %p
if b%2==1:
return (a*power_func(a,b-1,p))%p
h,w,a,b=map(int,input().split())
mod=10**9+7
if h-a<w-b:
h,w=w,h
a,b=b,a
t=0
for i in range(w-b):
t+=comb(h-a+w-b,b+i,mod)*comb(w-b+a-1,a+i,mod)
print(t%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> |
s784839087 | p04046 | Wrong Answer | base = 10**9 + 7
def comb(x, y):#xCy = [x-1]C[y-1] * n / k
res = 1
for i in range(x):
res = res * (x-i)
for i in range(y):
res = res // (y-i)
return res % base
H, W, A, B = map(int, input().split())
res = 0
for i in range(W-B):
res += comb(H-A-1 + W-i-1, W-i-1)*comb(A-1+i,i)
res %= base
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> |
s371150274 | p04046 | Wrong Answer | base = 10 ** 9 + 7
res = 0
H, W, A, B = map(int, input().split())
f1 = [1 for i in range(W)]
for i in range(H-1): #f1 -> #f2
f2 = [0 for j in range(W)]
for j in range(W):
if j == 0:
f2[0] = f1[0]
elif i > H-1-A and j<B:
f2[j] = f1[j]
else:
f2[j] = f1[j] + f2[j-1]
for j in range(W):
f1[j] = f2[j]%base
print(f1[W-1]) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the 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> |
s952005970 | p04046 | Wrong Answer | base = 10 ** 9 + 7
res = 0
H, W, A, B = map(int, input().split())
f1 = [0 for i in range(W)]
for i in range(H-1): #f1 -> #f2
f2 = [0 for j in range(W)]
for j in range(W):
if j == 0:
f2[0] = f1[0]
elif i > H-1-A and j<B:
f2[j] = f1[j]
else:
f2[j] = f1[j] + f2[j-1]
for j in range(W):
f1[j] = f2[j]%base
print(f2[W-1]) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the 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> |
s026996232 | p04046 | Wrong Answer | def examD(mod):
from operator import mul
from functools import reduce
def comb2(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
H, W, A, B =LI()
k = W-B
ans = int(0)
C1 = [0]*k; C2 = [0]*k
C1[0] = comb2(H - A + B + 0 - 1, H - A - 1) % mod
C2[0] = comb2(A + W - (B + 0) - 2, A - 1) % mod
C2[k-1] = 1
for i in range(1,k):
C1[i] = (C1[i-1]*(H-A+B+i-1)//(B+i))%mod
for i in range(k-1,1,-1):
C2[i-1] = (C2[i]*(A+W-(B+i-1)-2))//(W-(B+i))%mod
for i in range(k):
ans = (ans+C1[i]*C2[i])%mod
"""
for i in range(1,k):
C1[i] = comb2(H - A + B + i - 1, H - A - 1) % mod
C2[i] = comb2(A + W - (B + i) - 2, A - 1) % mod
ans = (ans+C1[i]*C2[i])%mod
"""
print(ans)
# print(C1)
# print(C2)
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')
examD(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> |
s963368214 | p04046 | Wrong Answer | H,W,A,B = map(int, input().split())
dp = [[0 for w in range(W)] for h in range(H)]
MOD = 10 ** 9 + 7
for w in range(W):
dp[0][w] = 1
for h in range(H-A):
dp[h][0] = 1
for h in range(1, H-A):
for w in range(1,W):
dp[h][w] = dp[h-1][w] % MOD + dp[h][w-1] % MOD
for h in range(H-A, H):
for w in range(B,W):
dp[h][w] = dp[h-1][w] % MOD + dp[h][w-1] % MOD
print(dp[H-1][W-1]) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the 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> |
s013028743 | p04046 | Wrong Answer | H, W, A, B = map(int, input().split())
MOD = 10**9+7
path = [[0 for w in range(W)] for h in range(H)]
for w in range(W):
path[0][w] = 1
for h in range(H-B):
path[h][0] = 1
for h in range(1, H-B):
for w in range(1, W):
path[h][w] = path[h-1][w]%MOD + path[h][w-1]%MOD
for h in range(1, H):
for w in range(A, W):
path[h][w] = path[h-1][w]%MOD + path[h][w-1]%MOD
print(path[H-1][W-1])
| 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the 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> |
s331178394 | p04046 | Wrong Answer | H, W, A, B = map(int, input().split())
path = [[0 for w in range(W)] for h in range(H)]
for w in range(W):
path[0][w] = 1
for h in range(H-B):
path[h][0] = 1
for h in range(1, H-B):
for w in range(1, W):
path[h][w] = path[h-1][w] + path[h][w-1]
for h in range(1, H):
for w in range(A, W):
path[h][w] = path[h-1][w] + path[h][w-1]
print(path[H-1][W-1]) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the 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> |
s637642516 | p04046 | Wrong Answer | #! /usr/bin/env python
# -*- coding: utf-8 -*-
import pdb
import sys
F = sys.stdin
H, W, A, B = F.readline().rstrip().split()
H = int(H)
W = int(W)
A = int(A)
B = int(B)
LL = 1e9 + 7
l = [[0] * W] * H
l[0] = [1] * W
for i in range(1, H - A):
for j in range(W):
if j == 0:
l[i][j] = 1
continue
l[i][j] = l[i - 1][j] + l[i][j - 1]
for k in range(H - A, H):
for m in range(B, W):
if m == B:
l[k][m] = l[k-1][m]
continue
l[k][m] = l[k-1][m] + l[k][m-1]
ans = int(l[H-1][W-1] % LL)
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> |
s275543214 | p04046 | Wrong Answer | import math
H, W, A, B = map(int,input().split())
def f(a,b):
p = math.factorial(a+b-2)
q = math.factorial(a-1)
r = math.factorial(b-1)
S = p // (q*r)
return S
T = 0
for i in range(1,B+1):
P = f(H-A,i)
Q = f(A,W-i+1)
T = T + P*Q
R = f(H,W) - T
ans = R % (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> |
s213686486 | p04046 | Wrong Answer | import math
H, W, A, B = map(int,input().split())
def f(a,b):
p = math.factorial(a+b-2)
q = math.factorial(a-1)
r = math.factorial(b-1)
S = p // (q*r)
return S
T = 0
for i in range(1,B+1):
P = f(H-A,i)
Q = f(A,W-i+1)
T = T + P*Q
R = f(H,W) - T
print(R) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the 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> |
s671570977 | p04046 | Wrong Answer | import math;
H, W, a, b = map(int, input().split(' '))
# 中継地点への行き方 * 中継地点からの行き方 ⇛各中継地点をたす
ans = 0
# 中間地点へのX、中間地点からのX
sgx = b - 1
gx = W - b - 1
sgxp = math.factorial(sgx)
gxp = math.factorial(gx)
sgyl = H - a
for i in range(sgyl):
tmp1 = 1
sgy = i
sxy = sgx + sgy
# for( n = sxy ; sgx != n; n--):
aaa = math.factorial(sxy)
bbb= math.factorial(sgy)
tmp1 = aaa // (bbb*sgxp)
gy = H -1 - i
sxy = gy + gx
aaa = math.factorial(sxy)
bbb= math.factorial(gy)
tmp2 = aaa // (bbb*gxp)
ans = ans + tmp1*tmp2
b = ans % 100000007
print(int(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> |
s702262753 | p04046 | Wrong Answer | import math;
H, W, a, b = map(int, input().split(' '))
# 中継地点への行き方 * 中継地点からの行き方 ⇛各中継地点をたす
ans = 0
# 中間地点へのX、中間地点からのX
sgx = b - 1
gx = W - b - 1
sgxp = math.factorial(sgx)
gxp = math.factorial(gx)
sgyl = H - a
for i in range(sgyl):
tmp1 = 1
sgy = i
sxy = sgx + sgy
# for( n = sxy ; sgx != n; n--):
for n in range(sgx):
tmp1 = tmp1 * (sxy - n)
tmp1 = tmp1 // sgxp
gy = H - i
sxy = gy + gx -1
tmp2 = 1
for n in range(gx):
tmp2 = tmp2 * (sxy - n)
tmp2 = tmp2 // gxp
ans = ans + tmp1*tmp2
b = ans % 100000007
print(int(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> |
s430850822 | p04046 | Wrong Answer | # D イロハちゃんと升目
cnt=0
h,w,a,b=map(int,input().split())
def find_power(n):
# 0!からn!までのびっくりを出してくれる関数
powlist=[0]*(n+1)
powlist[0]=1
powlist[1]=1
for i in range(2,n+1):
powlist[i]=powlist[i-1]*i%(10**9+7)
return powlist
def find_inv_power(n):
#0!からn!までの逆元を10**9+7で割ったあまりリストを作る関数
powlist=find_power(n)
check=powlist[-1]
first=1
uselist=[0]*(n+1)
secondlist=[0]*30
secondlist[0]=check
secondlist[1]=check**2
for i in range(28):
secondlist[i+2]=(secondlist[i+1]**2)%(10**9+7)
a=format(10**9+5,"b")
for j in range(30):
if a[29-j]=="1":
first=(first*secondlist[j])%(10**9+7)
uselist[n]=first
for i in range(n,0,-1):
uselist[i-1]=(uselist[i]*i)%(10**9+7)
return uselist
powlist=find_power(h+w+1)
invlist=find_inv_power(h+w+1)
def combi(n,r):
a=powlist
b=invlist
if n<r:
return 0
elif n>=r:
return (a[n]*b[r]*b[n-r])%(10**9+7)
for i in range(h-a):
cnt+=(combi(b+i-1,i)*combi(w+h-2-b-i,h-1-i))%(10**9+7)
print(cnt)
| 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
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> |
s164968857 | p04046 | Wrong Answer | import operator as op
from functools import reduce
MOD = (10 ** 9) + 7
factors = [1, 1]
finv = [1, 1]
inv = [0, 1]
for i in range(2, 200010):
factors.append(factors[i - 1] * i % MOD)
inv.append(MOD - inv[MOD % i] * (MOD // i) % MOD)
finv.append(finv[i - 1] * inv[i] % MOD)
def nck(n, k):
if n < k or n < 0 or k < 0:
return 0
return factors[n] * (finv[k] * finv[n - k] % MOD) % MOD
def ncr(n, r):
if n < r or n < 0 or r < 0:
return 0
r = min(r, n-r)
numer = reduce(op.mul, range(n, n-r, -1), 1)
denom = reduce(op.mul, range(1, r+1), 1)
return numer / denom
assert ncr(3, 4) == 0
def g(h, w, a, b):
prev = [1] * w
cur = [0] * w
for i in range(h - 1):
cur[0] = 1
start = 0
if i >= h - 1 - a:
cur[b] = prev[b]
start = b
for j in range(start + 1, w):
cur[j] = cur[j - 1] + prev[j]
cur[j] = cur[j] % (1e9 + 7)
prev, cur = cur, prev
return prev[-1]
def f(H, W, A, B):
count = 0
x, y, a = H - A - 1, W + A - 2, A - 1
for i in range(B, W): # bottom-left to top-right
c1 = nck(x + i, i)
c2 = nck(y - i, a)
c = c1 * c2
count += c
count = count % MOD
print(count)
return int(count)
## assert f(4, 4, 0, 0) == 20
# assert f(4, 4, 2, 2) == 10
#assert f(2, 3, 1, 1) == 2
#assert f(10, 7, 3, 4) == 3570
#assert f(100000, 100000, 99999, 99999) == 1
#assert f(100000, 100000, 44444, 55555) == 738162020
H, W, A, B = map(int, input().split())
ans = f(H, W, A, B)
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> |
s406557450 | p04046 | Wrong Answer | def cmb(n, r, mod):
if ( r<0 or r>n ):
return 0
else:
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7 #出力の制限
N = 200000
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
g1.append( ( g1[-1] * i ) % mod )
inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
g2.append( (g2[-1] * inverse[-1]) % mod )
H,W,A,B = map(int,input().split())
x = cmb(W+H-B-2,H-1,mod)
ans = x
#print(x)
for i in range(1,H-A):
x = (x * (B+i-1)*(H-i))//((W+H-B-i-1)*i)
x %= mod
ans += x
ans %= mod
#print(x)
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> |
s295690200 | p04046 | Wrong Answer | MOD = 10**9 + 7
factorials = [1]
for i in range(1, 200000):
factorials.append((factorials[-1] * i) % MOD)
def combinations(n, k):
return (factorials[n] / (factorials[k] * factorials[n - k])) % MOD
def f(x, y):
return combinations(x + y - 2, x - 1)
h, w, a, b = map(int, input().split())
res = 0
for y in range(1, h - a + 1):
res += (f(b, y) * f(w - b, h - y + 1)) % MOD
print(int(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> |
s254129664 | p04046 | Wrong Answer | import math
mod=10**9+7
h,w,a,b=map(int,input().split())
h1=h-a
h2=h
w1=b
w2=w-b
ans=0
for i in range(h1):
a=math.factorial(i+w1-1)%mod
b=math.factorial(i)%mod
c=math.factorial(w1-1)%mod
d=math.factorial(h-i-1+w2-1)%mod
e=math.factorial(h-i-1)%mod
f=math.factorial(w2-1)%mod
ans+=((a//(b*c))*(d//(e*f)))%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> |
s438504928 | p04046 | Wrong Answer | def main():
h,w,a,b=map(int,input().split(' '))
mod = 10**9+7
mx=max(h,w)
fac=[1]*(h+w+1)
for i in range(1,h+w+1):
fac[i]=fac[i-1]*i%mod
rev=[1]*(mx+1)
rev[-1]=pow(fac[mx],mod-2,mod)
for i in range(mx-1,-1,-1):
rev[i+1]=rev[i+1]*(i+1)%mod
const=rev[h-a-1]*rev[a-1]%mod
ans = sum(fac[h - a + i - 1] * rev[i] * fac[a + w - 2 - i] * rev[w - i - 1] % mod for i in range(b, w))
print(ans * const % 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> |
s929704301 | p04046 | Wrong Answer | H,W,A,B = map(int,input().split())
MOD = 10**9 + 7
FAC = [1]
INV = [1]
for i in range(1,H+W+1):
FAC.append((FAC[i-1]*i) % MOD)
INV.append(pow(FAC[-1],MOD-2,MOD))
#print(FAC)
#print(INV)
def nCr(n,r):
return FAC[n]*INV[n-r]*INV[r]
ans = 0
for i in range(H-A):
ans += (nCr(i+B-1,min(i,B-1)) * nCr(H-i-1+W-B-1,min(H-i-1,W-B-1))) % 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> |
s114229006 | p04046 | Wrong Answer | # coding: utf-8
# Your code here!
H,W,A,B=map(int,input().split())
def tansaku(x,y):#これずっと使ったら時間足りなくなりそう
ans=1
upper=(x+y)
under=min(x,y)
for i in range(under):
ans*=(upper-i)/(under-i)
return ans
l_block=1
r_block=tansaku(H-1,W-B-1)
ans=l_block*r_block
for i in range(1,H-A):
l_block*=(B+i)/i
r_block*=(H-i)/(H+W-B-i-1)
ans+=(l_block-l_block*i/(B+i))*r_block
print(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> |
s676698636 | p04046 | Wrong Answer | import sys
import heapq
import bisect
mod = 10**9+7
dd = ((-1,0),(1,0),(0,-1),(0,1))
def I(): return(int(sys.stdin.readline()))
def LI(): return([int(x) for x in sys.stdin.readline().split()])
def S(): return(sys.stdin.readline()[:-1])
def IR(n): return([I() for _ in range(n)])
def GCD(a,b):
while b!=0:
a,b = b,a%b
return a
def LCM(a,b):
return a * b // GCD(a,b)
def Eratosthenes(N):
r = [True]*(N+1)
r[0] = False
r[1] = False
i = 2
while i*i<=N:
if r[i]:
j = i
while i*j<=N:
prime[i*j]=False
j+=1
i+=1
return(r)
def main():
H,W,A,B = LI()
ans = [0]*(W-B)
ans[0] = 1
for i in range(1,B+H-A):
ans[0] *= i
ans[0] %= mod
for i in range(1,A-1+W-B):
ans[0] *= i
ans[0] %= mod
for i in range(1,H-A):
ans[0] *= pow(i,mod-2,mod)
ans[0] %= mod
for i in range(1,B+1):
ans[0] *= pow(i,mod-2,mod)
ans[0] %= mod
for i in range(1,W-B):
ans[0] *= pow(i,mod-2,mod)
ans[0] %= mod
for i in range(1,A):
ans[0] *= pow(i,mod-2,mod)
ans[0] %= mod
for i in range(1,W-B):
ans[i] = ans[i-1]
ans[i] *= (B+H-A-1+i)
ans[i] %= mod
ans[i] *= (W-B-i)
ans[i] %= mod
ans[i] *= pow(H-A-1+i,mod-2,mod)
ans[i] %= mod
ans[i] *= pow(A-1+W-B-i,mod-2,mod)
ans[i] %= mod
return(sum(ans)%mod)
if __name__ == "__main__":
print(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> |
s437216117 | p04046 | Wrong Answer | h,w,a,b =map(int,input().split())
mod = 10**9+7
#階乗を求める
fact_l = [1 for i in range(h+w+1)]
for i in range(1,len(fact_l)):
fact_l[i] *= (fact_l[i-1]*i)%mod
#逆元
factinv_l = [1 for i in range(h+w+1)]
for i in range(1,len(fact_l)):
factinv_l[i] = pow(fact_l[i],mod-2,mod)
#必ず通るポイントまでの組み合わせ
point1 = [1 for i in range(w-b)]
for i in range(len(point1)):
yoko = b+i
tate = h-a-1
n = yoko+tate
r = yoko
point1[i] = fact_l[n]*factinv_l[r]*factinv_l[n-r]%mod
#point1からの経路
out = 0
for i in range(len(point1)):
yoko = w-b-i-1
tate = a-1
n = yoko+tate
r = yoko
case = fact_l[n]*factinv_l[r]*factinv_l[n-r]%mod
out += point1[i]*case%mod
print(out) | 2 3 1 1
| 2
| <span class="lang-en">
<p>Score : <var>400</var> points</p>
<div class="part">
<section>
<h3>Problem Statement</h3><p>We have a large square grid with <var>H</var> rows and <var>W</var> columns.
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.