submission_id
string
problem_id
string
status
string
code
string
input
string
output
string
problem_description
string
s313470683
p04051
Time Limit Exceeded
from collections import defaultdict def solve(): Base = 2000 MAX = Base*2 p = 10**9+7 F = [1]; Finv = [0]*(MAX*2+1) for i in xrange(MAX*2): F.append(F[i]*(i+1)%p) Finv[MAX*2] = pow(F[MAX*2],p-2,p) for i in xrange(MAX*2,0,-1): Finv[i-1] = Finv[i]*i%p N = int(raw_input()) dup = A_MAX = B_MAX = 0 dp = [[0]*(MAX+2) for i in xrange(MAX+2)] goals = defaultdict(int) for i in xrange(N): A,B = map(int,raw_input().split()) dup = (dup + F[A*2+B*2]*Finv[A*2]*Finv[B*2]%p)%p if A > A_MAX: A_MAX = A if B > B_MAX: B_MAX = B goals[(Base+A,Base+B)] += 1 dp[Base-B][Base-A] += 1 for j in xrange(Base-B_MAX,Base+B_MAX+1): for i in xrange(Base-A_MAX,Base+A_MAX+1): dp[j+1][i] = (dp[j+1][i] + dp[j][i]) % p dp[j][i+1] = (dp[j][i+1] + dp[j][i]) % p ans = 0 for (i,j),v in goals.iteritems(): ans = (ans + dp[j][i]*v) % p print ((ans - dup)*pow(2,p-2,p) + p) % p solve()
3 1 1 1 1 2 1
26
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is having another barbeque party.</p> <p>This time, he will make one serving of <em>Skewer Meal</em>.</p> <p>He has a stock of <var>N</var> <em>Skewer Meal Packs</em>. The <var>i</var>-th Skewer Meal Pack contains one skewer, <var>A_i</var> pieces of beef and <var>B_i</var> pieces of green pepper. All skewers in these packs are different and distinguishable, while all pieces of beef and all pieces of green pepper are, respectively, indistinguishable.</p> <p>To make a Skewer Meal, he chooses two of his Skewer Meal Packs, and takes out all of the contents from the chosen packs, that is, two skewers and some pieces of beef or green pepper. (Remaining Skewer Meal Packs will not be used.) Then, all those pieces of food are threaded onto both skewers, one by one, in any order.</p> <p>(See the image in the Sample section for better understanding.)</p> <p>In how many different ways can he make a Skewer Meal? Two ways of making a Skewer Meal is different if and only if the sets of the used skewers are different, or the orders of the pieces of food are different. Since this number can be extremely large, find it modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦200,000</var></li> <li><var>1≦A_i≦2000, 1≦B_i≦2000</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>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> : <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the different ways Snuke can make a serving of Skewer Meal, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 1 1 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>26 </pre> <p>The <var>26</var> ways of making a Skewer Meal are shown below. Gray bars represent skewers, each with a number denoting the Skewer Meal Set that contained the skewer. Brown and green rectangles represent pieces of beef and green pepper, respectively.</p> <div style="text-align: center;"> <img alt="ebbq.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/ebbq.png"> </img></div></section> </div> </span>
s498436523
p04051
Time Limit Exceeded
from collections import defaultdict def solve(): Base = 2000 MAX = Base*2 p = 10**9+7 F = [1]; Finv = [0]*(MAX+1) for i in xrange(MAX*2): F.append(F[i]*(i+1)%p) Finv[MAX] = pow(F[MAX],p-2,p) for i in xrange(MAX,0,-1): Finv[i-1] = Finv[i]*i%p N = int(raw_input()) dup = 0 dp = [[0]*(MAX+2) for i in xrange(MAX+2)] goals = defaultdict(int) for i in xrange(N): A,B = map(int,raw_input().split()) dup = (dup + F[A*2+B*2]*Finv[A*2]*Finv[B*2]%p)%p goals[(Base+A,Base+B)] += 1 dp[Base-B][Base-A] += 1 for j in xrange(MAX+1): for i in xrange(MAX+1): dp[j+1][i] += dp[j][i] dp[j][i+1] += dp[j][i] ans = 0 for (i,j),v in goals.iteritems(): ans = (ans + dp[j][i]*v) % p print ((ans - dup) / 2 + p) % p solve()
3 1 1 1 1 2 1
26
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is having another barbeque party.</p> <p>This time, he will make one serving of <em>Skewer Meal</em>.</p> <p>He has a stock of <var>N</var> <em>Skewer Meal Packs</em>. The <var>i</var>-th Skewer Meal Pack contains one skewer, <var>A_i</var> pieces of beef and <var>B_i</var> pieces of green pepper. All skewers in these packs are different and distinguishable, while all pieces of beef and all pieces of green pepper are, respectively, indistinguishable.</p> <p>To make a Skewer Meal, he chooses two of his Skewer Meal Packs, and takes out all of the contents from the chosen packs, that is, two skewers and some pieces of beef or green pepper. (Remaining Skewer Meal Packs will not be used.) Then, all those pieces of food are threaded onto both skewers, one by one, in any order.</p> <p>(See the image in the Sample section for better understanding.)</p> <p>In how many different ways can he make a Skewer Meal? Two ways of making a Skewer Meal is different if and only if the sets of the used skewers are different, or the orders of the pieces of food are different. Since this number can be extremely large, find it modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦200,000</var></li> <li><var>1≦A_i≦2000, 1≦B_i≦2000</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>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> : <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the different ways Snuke can make a serving of Skewer Meal, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 1 1 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>26 </pre> <p>The <var>26</var> ways of making a Skewer Meal are shown below. Gray bars represent skewers, each with a number denoting the Skewer Meal Set that contained the skewer. Brown and green rectangles represent pieces of beef and green pepper, respectively.</p> <div style="text-align: center;"> <img alt="ebbq.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/ebbq.png"> </img></div></section> </div> </span>
s450910072
p04051
Time Limit Exceeded
import math set_num = int(raw_input()) bbqsets = [] _append = bbqsets.append for _ in xrange(set_num): _append([ int(x) for x in raw_input().split() ]) maxnum = math.pow(10, 9) + 7 cache = {} total = 0 fact = math.factorial for x in xrange(set_num): setA = bbqsets[x] for y in xrange(x + 1, set_num): setB = bbqsets[y] nums = tuple(sorted([setA[0] + setB[0], setA[1] + setB[1]])) cmb = 0 if nums in cache: cmb = cache[nums] else: cmb = fact(nums[0] + nums[1]) / fact(nums[0]) / fact(nums[1]) cache[nums] = cmb # print meats, veges total += cmb if total > maxnum: total = total % maxnum print total
3 1 1 1 1 2 1
26
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is having another barbeque party.</p> <p>This time, he will make one serving of <em>Skewer Meal</em>.</p> <p>He has a stock of <var>N</var> <em>Skewer Meal Packs</em>. The <var>i</var>-th Skewer Meal Pack contains one skewer, <var>A_i</var> pieces of beef and <var>B_i</var> pieces of green pepper. All skewers in these packs are different and distinguishable, while all pieces of beef and all pieces of green pepper are, respectively, indistinguishable.</p> <p>To make a Skewer Meal, he chooses two of his Skewer Meal Packs, and takes out all of the contents from the chosen packs, that is, two skewers and some pieces of beef or green pepper. (Remaining Skewer Meal Packs will not be used.) Then, all those pieces of food are threaded onto both skewers, one by one, in any order.</p> <p>(See the image in the Sample section for better understanding.)</p> <p>In how many different ways can he make a Skewer Meal? Two ways of making a Skewer Meal is different if and only if the sets of the used skewers are different, or the orders of the pieces of food are different. Since this number can be extremely large, find it modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦200,000</var></li> <li><var>1≦A_i≦2000, 1≦B_i≦2000</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>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> : <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the different ways Snuke can make a serving of Skewer Meal, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 1 1 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>26 </pre> <p>The <var>26</var> ways of making a Skewer Meal are shown below. Gray bars represent skewers, each with a number denoting the Skewer Meal Set that contained the skewer. Brown and green rectangles represent pieces of beef and green pepper, respectively.</p> <div style="text-align: center;"> <img alt="ebbq.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/ebbq.png"> </img></div></section> </div> </span>
s950889610
p04051
Time Limit Exceeded
import math set_num = int(raw_input()) bbqsets = [] _append = bbqsets.append for _ in xrange(set_num): _append([ int(x) for x in raw_input().split() ]) maxnum = math.pow(10, 9) + 7 cache = {} total = 0 for x in xrange(set_num): setA = bbqsets[x] for y in xrange(x + 1, set_num): setB = bbqsets[y] nums = tuple(sorted([setA[0] + setB[0], setA[1] + setB[1]])) cmb = 0 if nums in cache: cmb = cache[nums] else: cmb = 1.0 for n in xrange(1, nums[0] + 1): cmb *= float(nums[1] + n) / n # print nums, cmb cmb = round(cmb) cache[nums] = cmb # print meats, veges total += cmb if total > maxnum: total = total % maxnum print int(total)
3 1 1 1 1 2 1
26
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is having another barbeque party.</p> <p>This time, he will make one serving of <em>Skewer Meal</em>.</p> <p>He has a stock of <var>N</var> <em>Skewer Meal Packs</em>. The <var>i</var>-th Skewer Meal Pack contains one skewer, <var>A_i</var> pieces of beef and <var>B_i</var> pieces of green pepper. All skewers in these packs are different and distinguishable, while all pieces of beef and all pieces of green pepper are, respectively, indistinguishable.</p> <p>To make a Skewer Meal, he chooses two of his Skewer Meal Packs, and takes out all of the contents from the chosen packs, that is, two skewers and some pieces of beef or green pepper. (Remaining Skewer Meal Packs will not be used.) Then, all those pieces of food are threaded onto both skewers, one by one, in any order.</p> <p>(See the image in the Sample section for better understanding.)</p> <p>In how many different ways can he make a Skewer Meal? Two ways of making a Skewer Meal is different if and only if the sets of the used skewers are different, or the orders of the pieces of food are different. Since this number can be extremely large, find it modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦200,000</var></li> <li><var>1≦A_i≦2000, 1≦B_i≦2000</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>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> : <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the different ways Snuke can make a serving of Skewer Meal, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 1 1 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>26 </pre> <p>The <var>26</var> ways of making a Skewer Meal are shown below. Gray bars represent skewers, each with a number denoting the Skewer Meal Set that contained the skewer. Brown and green rectangles represent pieces of beef and green pepper, respectively.</p> <div style="text-align: center;"> <img alt="ebbq.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/ebbq.png"> </img></div></section> </div> </span>
s478505632
p04051
Time Limit Exceeded
import scipy.misc as scm def combi(p,q): return scm.comb(p,q,1) ans=0 n=int(input()) k=[] for i in range(n): a,b=map(int,input().split()) k.append([a,b]) for i in range(n-1): for j in range(i+1,n): p=k[i][0]+k[i][1]+k[j][0]+k[j][1] q=k[i][0]+k[j][0] ans += combi(p,q) % (10**9+7) ans = ans % (10**9+7) print(ans)
3 1 1 1 1 2 1
26
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is having another barbeque party.</p> <p>This time, he will make one serving of <em>Skewer Meal</em>.</p> <p>He has a stock of <var>N</var> <em>Skewer Meal Packs</em>. The <var>i</var>-th Skewer Meal Pack contains one skewer, <var>A_i</var> pieces of beef and <var>B_i</var> pieces of green pepper. All skewers in these packs are different and distinguishable, while all pieces of beef and all pieces of green pepper are, respectively, indistinguishable.</p> <p>To make a Skewer Meal, he chooses two of his Skewer Meal Packs, and takes out all of the contents from the chosen packs, that is, two skewers and some pieces of beef or green pepper. (Remaining Skewer Meal Packs will not be used.) Then, all those pieces of food are threaded onto both skewers, one by one, in any order.</p> <p>(See the image in the Sample section for better understanding.)</p> <p>In how many different ways can he make a Skewer Meal? Two ways of making a Skewer Meal is different if and only if the sets of the used skewers are different, or the orders of the pieces of food are different. Since this number can be extremely large, find it modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦200,000</var></li> <li><var>1≦A_i≦2000, 1≦B_i≦2000</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>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> : <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the different ways Snuke can make a serving of Skewer Meal, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 1 1 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>26 </pre> <p>The <var>26</var> ways of making a Skewer Meal are shown below. Gray bars represent skewers, each with a number denoting the Skewer Meal Set that contained the skewer. Brown and green rectangles represent pieces of beef and green pepper, respectively.</p> <div style="text-align: center;"> <img alt="ebbq.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/ebbq.png"> </img></div></section> </div> </span>
s890197679
p04051
Time Limit Exceeded
def calc(ab1,ab2): meat = ab1[0] + ab2[0] vege = ab1[1] + ab2[1] pattern = fact_list[meat+vege] / (fact_list[meat] * fact_list[vege]) return pattern if __name__ == '__main__': N = int(input()) AB = [list(map(int, input().split())) for i in range(N)] fact_list = {} fact_list[0] = 1 # max_ab = max(AB[x][0] + AB[x][1] for x in range(N)) for i in range(1,4001): fact_list[i] = (fact_list[i-1] * i) % (10**9 + 7) sum_count = 0 for i in range(N): for j in range(i+1,N): sum_count += calc(AB[i],AB[j]) sum_count = sum_count % (10**9 + 7) print( int(sum_count % (10**9 + 7)) )
3 1 1 1 1 2 1
26
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is having another barbeque party.</p> <p>This time, he will make one serving of <em>Skewer Meal</em>.</p> <p>He has a stock of <var>N</var> <em>Skewer Meal Packs</em>. The <var>i</var>-th Skewer Meal Pack contains one skewer, <var>A_i</var> pieces of beef and <var>B_i</var> pieces of green pepper. All skewers in these packs are different and distinguishable, while all pieces of beef and all pieces of green pepper are, respectively, indistinguishable.</p> <p>To make a Skewer Meal, he chooses two of his Skewer Meal Packs, and takes out all of the contents from the chosen packs, that is, two skewers and some pieces of beef or green pepper. (Remaining Skewer Meal Packs will not be used.) Then, all those pieces of food are threaded onto both skewers, one by one, in any order.</p> <p>(See the image in the Sample section for better understanding.)</p> <p>In how many different ways can he make a Skewer Meal? Two ways of making a Skewer Meal is different if and only if the sets of the used skewers are different, or the orders of the pieces of food are different. Since this number can be extremely large, find it modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦200,000</var></li> <li><var>1≦A_i≦2000, 1≦B_i≦2000</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>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> : <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the different ways Snuke can make a serving of Skewer Meal, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 1 1 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>26 </pre> <p>The <var>26</var> ways of making a Skewer Meal are shown below. Gray bars represent skewers, each with a number denoting the Skewer Meal Set that contained the skewer. Brown and green rectangles represent pieces of beef and green pepper, respectively.</p> <div style="text-align: center;"> <img alt="ebbq.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/ebbq.png"> </img></div></section> </div> </span>
s706405673
p04051
Time Limit Exceeded
def calc(ab1,ab2): meat = ab1[0] + ab2[0] vege = ab1[1] + ab2[1] pattern = fact_list[meat+vege] / (fact_list[meat] * fact_list[vege]) return pattern if __name__ == '__main__': N = int(input()) AB = [list(map(int, input().split())) for i in range(N)] fact_list = {} fact_list[0] = 1 # max_ab = max(AB[x][0] + AB[x][1] for x in range(N)) for i in range(1,4001): fact_list[i] = fact_list[i-1] * i sum_count = 0 for i in range(N): for j in range(i+1,N): sum_count += calc(AB[i],AB[j]) sum_count = sum_count % (10**9 + 7) print( int(sum_count % (10**9 + 7)) )
3 1 1 1 1 2 1
26
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is having another barbeque party.</p> <p>This time, he will make one serving of <em>Skewer Meal</em>.</p> <p>He has a stock of <var>N</var> <em>Skewer Meal Packs</em>. The <var>i</var>-th Skewer Meal Pack contains one skewer, <var>A_i</var> pieces of beef and <var>B_i</var> pieces of green pepper. All skewers in these packs are different and distinguishable, while all pieces of beef and all pieces of green pepper are, respectively, indistinguishable.</p> <p>To make a Skewer Meal, he chooses two of his Skewer Meal Packs, and takes out all of the contents from the chosen packs, that is, two skewers and some pieces of beef or green pepper. (Remaining Skewer Meal Packs will not be used.) Then, all those pieces of food are threaded onto both skewers, one by one, in any order.</p> <p>(See the image in the Sample section for better understanding.)</p> <p>In how many different ways can he make a Skewer Meal? Two ways of making a Skewer Meal is different if and only if the sets of the used skewers are different, or the orders of the pieces of food are different. Since this number can be extremely large, find it modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦200,000</var></li> <li><var>1≦A_i≦2000, 1≦B_i≦2000</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>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> : <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the different ways Snuke can make a serving of Skewer Meal, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 1 1 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>26 </pre> <p>The <var>26</var> ways of making a Skewer Meal are shown below. Gray bars represent skewers, each with a number denoting the Skewer Meal Set that contained the skewer. Brown and green rectangles represent pieces of beef and green pepper, respectively.</p> <div style="text-align: center;"> <img alt="ebbq.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/ebbq.png"> </img></div></section> </div> </span>
s262144512
p04051
Time Limit Exceeded
def calc(ab1,ab2): meat = ab1[0] + ab2[0] vege = ab1[1] + ab2[1] pattern = fact_list[meat+vege] / (fact_list[meat] * fact_list[vege]) return pattern if __name__ == '__main__': N = int(input()) AB = [list(map(int, input().split())) for i in range(N)] fact_list = {} fact_list[0] = 1 # max_ab = max(AB[x][0] + AB[x][1] for x in range(N)) for i in range(1,4001): fact_list[i] = fact_list[i-1] * i sum_count = 0 for i in range(N): for j in range(i+1,N): sum_count += calc(AB[i],AB[j]) print( int(sum_count % (10**9 + 7)) )
3 1 1 1 1 2 1
26
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is having another barbeque party.</p> <p>This time, he will make one serving of <em>Skewer Meal</em>.</p> <p>He has a stock of <var>N</var> <em>Skewer Meal Packs</em>. The <var>i</var>-th Skewer Meal Pack contains one skewer, <var>A_i</var> pieces of beef and <var>B_i</var> pieces of green pepper. All skewers in these packs are different and distinguishable, while all pieces of beef and all pieces of green pepper are, respectively, indistinguishable.</p> <p>To make a Skewer Meal, he chooses two of his Skewer Meal Packs, and takes out all of the contents from the chosen packs, that is, two skewers and some pieces of beef or green pepper. (Remaining Skewer Meal Packs will not be used.) Then, all those pieces of food are threaded onto both skewers, one by one, in any order.</p> <p>(See the image in the Sample section for better understanding.)</p> <p>In how many different ways can he make a Skewer Meal? Two ways of making a Skewer Meal is different if and only if the sets of the used skewers are different, or the orders of the pieces of food are different. Since this number can be extremely large, find it modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦200,000</var></li> <li><var>1≦A_i≦2000, 1≦B_i≦2000</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>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> : <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the different ways Snuke can make a serving of Skewer Meal, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 1 1 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>26 </pre> <p>The <var>26</var> ways of making a Skewer Meal are shown below. Gray bars represent skewers, each with a number denoting the Skewer Meal Set that contained the skewer. Brown and green rectangles represent pieces of beef and green pepper, respectively.</p> <div style="text-align: center;"> <img alt="ebbq.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/ebbq.png"> </img></div></section> </div> </span>
s322096708
p04051
Time Limit Exceeded
import math set_num = int(raw_input()) bbqsets = [] _append = bbqsets.append for _ in xrange(set_num): _append([ int(x) for x in raw_input().split() ]) maxnum = math.pow(10, 9) + 7 cache = {} def get_combinations(meats, veges): nums = sorted([meats, veges]) key = '{}:{}'.format(nums[0], nums[1]) if key in cache: return cache[key] allnum = meats + veges greater = nums[1] result = 1.0 for n in xrange(1, nums[0] + 1): t = greater + n result *= float(t) / n # print key, result result = round(result) cache[key] = result return result total = 0 for x in xrange(set_num): setA = bbqsets[x] for y in xrange(x + 1, set_num): setB = bbqsets[y] meats = setA[0] + setB[0] veges = setA[1] + setB[1] # print meats, veges combinations = get_combinations(meats, veges) total += combinations if total > maxnum: total = total % maxnum print int(total)
3 1 1 1 1 2 1
26
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is having another barbeque party.</p> <p>This time, he will make one serving of <em>Skewer Meal</em>.</p> <p>He has a stock of <var>N</var> <em>Skewer Meal Packs</em>. The <var>i</var>-th Skewer Meal Pack contains one skewer, <var>A_i</var> pieces of beef and <var>B_i</var> pieces of green pepper. All skewers in these packs are different and distinguishable, while all pieces of beef and all pieces of green pepper are, respectively, indistinguishable.</p> <p>To make a Skewer Meal, he chooses two of his Skewer Meal Packs, and takes out all of the contents from the chosen packs, that is, two skewers and some pieces of beef or green pepper. (Remaining Skewer Meal Packs will not be used.) Then, all those pieces of food are threaded onto both skewers, one by one, in any order.</p> <p>(See the image in the Sample section for better understanding.)</p> <p>In how many different ways can he make a Skewer Meal? Two ways of making a Skewer Meal is different if and only if the sets of the used skewers are different, or the orders of the pieces of food are different. Since this number can be extremely large, find it modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦200,000</var></li> <li><var>1≦A_i≦2000, 1≦B_i≦2000</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>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> : <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the different ways Snuke can make a serving of Skewer Meal, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 1 1 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>26 </pre> <p>The <var>26</var> ways of making a Skewer Meal are shown below. Gray bars represent skewers, each with a number denoting the Skewer Meal Set that contained the skewer. Brown and green rectangles represent pieces of beef and green pepper, respectively.</p> <div style="text-align: center;"> <img alt="ebbq.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/ebbq.png"> </img></div></section> </div> </span>
s948075523
p04051
Accepted
import sys from collections import defaultdict import numpy as np def prepare(n, MOD): f = 1 factorials = [1] for m in range(1, n + 1): f *= m f %= MOD factorials.append(f) inv = pow(f, MOD - 2, MOD) 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 MOD = 10 ** 9 + 7 n = int(sys.stdin.buffer.readline()) ab = list(map(int, sys.stdin.buffer.read().split())) aaa = ab[0::2] bbb = ab[1::2] max_a = max(aaa) max_b = max(bbb) facts, invs = prepare(2 * (max_a + max_b), MOD) dp_size = max_b * 2 + 1 ans = 0 dd_create_func = lambda: np.zeros(dp_size, dtype=np.int64) get_ab = defaultdict(dd_create_func) for a, b in zip(aaa, bbb): get_ab[a][b + max_b] += 1 ans = (ans - facts[2 * (a + b)] * invs[2 * a] * invs[2 * b]) % MOD dp = np.zeros(dp_size, dtype=np.int64) for i in range(-max_a, max_a + 1): if i < 0 and -i in get_ab: dp += get_ab[-i][::-1] dp = np.add.accumulate(dp) % MOD if i > 0 and i in get_ab: ans = (ans + (dp * get_ab[i]).sum()) % MOD print(ans * invs[2] % MOD)
3 1 1 1 1 2 1
26
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is having another barbeque party.</p> <p>This time, he will make one serving of <em>Skewer Meal</em>.</p> <p>He has a stock of <var>N</var> <em>Skewer Meal Packs</em>. The <var>i</var>-th Skewer Meal Pack contains one skewer, <var>A_i</var> pieces of beef and <var>B_i</var> pieces of green pepper. All skewers in these packs are different and distinguishable, while all pieces of beef and all pieces of green pepper are, respectively, indistinguishable.</p> <p>To make a Skewer Meal, he chooses two of his Skewer Meal Packs, and takes out all of the contents from the chosen packs, that is, two skewers and some pieces of beef or green pepper. (Remaining Skewer Meal Packs will not be used.) Then, all those pieces of food are threaded onto both skewers, one by one, in any order.</p> <p>(See the image in the Sample section for better understanding.)</p> <p>In how many different ways can he make a Skewer Meal? Two ways of making a Skewer Meal is different if and only if the sets of the used skewers are different, or the orders of the pieces of food are different. Since this number can be extremely large, find it modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦200,000</var></li> <li><var>1≦A_i≦2000, 1≦B_i≦2000</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>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> : <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the different ways Snuke can make a serving of Skewer Meal, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 1 1 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>26 </pre> <p>The <var>26</var> ways of making a Skewer Meal are shown below. Gray bars represent skewers, each with a number denoting the Skewer Meal Set that contained the skewer. Brown and green rectangles represent pieces of beef and green pepper, respectively.</p> <div style="text-align: center;"> <img alt="ebbq.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/ebbq.png"> </img></div></section> </div> </span>
s860871725
p04051
Accepted
import sys from collections import defaultdict import numpy as np def prepare(n, MOD): f = 1 factorials = [1] for m in range(1, n + 1): f *= m f %= MOD factorials.append(f) inv = pow(f, MOD - 2, MOD) 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 MOD = 10 ** 9 + 7 n = int(sys.stdin.buffer.readline()) ab = list(map(int, sys.stdin.buffer.read().split())) aaa = ab[0::2] bbb = ab[1::2] max_a = max(aaa) max_b = max(bbb) facts, invs = prepare(2 * (max_a + max_b), MOD) dp_size = max_b * 2 + 1 ans = 0 dd_create_func = lambda: np.zeros(dp_size, dtype=np.int64) put_ab = defaultdict(dd_create_func) get_ab = defaultdict(dd_create_func) for a, b in zip(aaa, bbb): put_ab[-a][-b + max_b] += 1 get_ab[a][b + max_b] += 1 ans = (ans - facts[2 * (a + b)] * invs[2 * a] * invs[2 * b]) % MOD dp = np.zeros(dp_size, dtype=np.int64) for i in range(-max_a, max_a + 1): if i < 0 and i in put_ab: dp += put_ab[i] dp = np.add.accumulate(dp) % MOD if i > 0 and i in get_ab: ans = (ans + (dp * get_ab[i]).sum()) % MOD print(ans * invs[2] % MOD)
3 1 1 1 1 2 1
26
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is having another barbeque party.</p> <p>This time, he will make one serving of <em>Skewer Meal</em>.</p> <p>He has a stock of <var>N</var> <em>Skewer Meal Packs</em>. The <var>i</var>-th Skewer Meal Pack contains one skewer, <var>A_i</var> pieces of beef and <var>B_i</var> pieces of green pepper. All skewers in these packs are different and distinguishable, while all pieces of beef and all pieces of green pepper are, respectively, indistinguishable.</p> <p>To make a Skewer Meal, he chooses two of his Skewer Meal Packs, and takes out all of the contents from the chosen packs, that is, two skewers and some pieces of beef or green pepper. (Remaining Skewer Meal Packs will not be used.) Then, all those pieces of food are threaded onto both skewers, one by one, in any order.</p> <p>(See the image in the Sample section for better understanding.)</p> <p>In how many different ways can he make a Skewer Meal? Two ways of making a Skewer Meal is different if and only if the sets of the used skewers are different, or the orders of the pieces of food are different. Since this number can be extremely large, find it modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦200,000</var></li> <li><var>1≦A_i≦2000, 1≦B_i≦2000</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>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> : <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the different ways Snuke can make a serving of Skewer Meal, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 1 1 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>26 </pre> <p>The <var>26</var> ways of making a Skewer Meal are shown below. Gray bars represent skewers, each with a number denoting the Skewer Meal Set that contained the skewer. Brown and green rectangles represent pieces of beef and green pepper, respectively.</p> <div style="text-align: center;"> <img alt="ebbq.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/ebbq.png"> </img></div></section> </div> </span>
s227650434
p04051
Accepted
import sys from collections import defaultdict import numpy as np def prepare(n, MOD): f = 1 factorials = [1] for m in range(1, n + 1): f *= m f %= MOD factorials.append(f) inv = pow(f, MOD - 2, MOD) 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 n = int(sys.stdin.buffer.readline()) mp = map(int, sys.stdin.buffer.read().split()) ab = list(zip(mp, mp)) atob = defaultdict(list) max_a, max_b = 0, 0 for a, b in ab: atob[a].append(b) max_a = max(max_a, a) max_b = max(max_b, b) MOD = 10 ** 9 + 7 dp = np.zeros(max_b * 2 + 1, dtype=np.int64) ans = 0 for i in range(-max_a, max_a + 1): if i < 0 and -i in atob: for j in atob[-i]: dp[-j + max_b] += 1 dp = np.add.accumulate(dp) % MOD if i > 0 and i in atob: for j in atob[i]: ans = (ans + dp[j + max_b]) % MOD facts, invs = prepare(2 * (max_a + max_b), MOD) ans = int(ans) for a, b in ab: ans = (ans - facts[2 * (a + b)] * invs[2 * a] * invs[2 * b]) % MOD print(ans * invs[2] % MOD)
3 1 1 1 1 2 1
26
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is having another barbeque party.</p> <p>This time, he will make one serving of <em>Skewer Meal</em>.</p> <p>He has a stock of <var>N</var> <em>Skewer Meal Packs</em>. The <var>i</var>-th Skewer Meal Pack contains one skewer, <var>A_i</var> pieces of beef and <var>B_i</var> pieces of green pepper. All skewers in these packs are different and distinguishable, while all pieces of beef and all pieces of green pepper are, respectively, indistinguishable.</p> <p>To make a Skewer Meal, he chooses two of his Skewer Meal Packs, and takes out all of the contents from the chosen packs, that is, two skewers and some pieces of beef or green pepper. (Remaining Skewer Meal Packs will not be used.) Then, all those pieces of food are threaded onto both skewers, one by one, in any order.</p> <p>(See the image in the Sample section for better understanding.)</p> <p>In how many different ways can he make a Skewer Meal? Two ways of making a Skewer Meal is different if and only if the sets of the used skewers are different, or the orders of the pieces of food are different. Since this number can be extremely large, find it modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦200,000</var></li> <li><var>1≦A_i≦2000, 1≦B_i≦2000</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>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> : <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the different ways Snuke can make a serving of Skewer Meal, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 1 1 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>26 </pre> <p>The <var>26</var> ways of making a Skewer Meal are shown below. Gray bars represent skewers, each with a number denoting the Skewer Meal Set that contained the skewer. Brown and green rectangles represent pieces of beef and green pepper, respectively.</p> <div style="text-align: center;"> <img alt="ebbq.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/ebbq.png"> </img></div></section> </div> </span>
s450623609
p04051
Accepted
mod = 10**9+7 mod2 = 998244353 rng = 100100 fctr = [1] finv = [1] for i in range(1,rng): fctr.append(fctr[-1]*i%mod) for i in range(1,rng): finv.append(pow(fctr[i],mod-2,mod)) def cmb(n,k): if n<0 or k<0: return 0 else: return fctr[n]*finv[n-k]*finv[k]%mod n = int(input()) ab = [list(map(int,input().split())) for i in range(n)] s = 0 for a,b in ab: s = max(s,a,b) dp = [[0 for i in range(2*s+2)] for j in range(2*s+2)] for a,b in ab: dp[s+1-a][s+1-b] += 1 for i in range(1,2*s+2): for j in range(1,2*s+2): dp[i][j] = (dp[i][j]+dp[i-1][j]+dp[i][j-1])%mod x = 0 for a,b in ab: x = (x+dp[s+1+a][s+1+b])%mod t = 0 for a,b in ab: t = (t+cmb(2*a+2*b,2*a))%mod ans = (x-t)*pow(2,mod-2,mod)%mod print(ans)
3 1 1 1 1 2 1
26
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is having another barbeque party.</p> <p>This time, he will make one serving of <em>Skewer Meal</em>.</p> <p>He has a stock of <var>N</var> <em>Skewer Meal Packs</em>. The <var>i</var>-th Skewer Meal Pack contains one skewer, <var>A_i</var> pieces of beef and <var>B_i</var> pieces of green pepper. All skewers in these packs are different and distinguishable, while all pieces of beef and all pieces of green pepper are, respectively, indistinguishable.</p> <p>To make a Skewer Meal, he chooses two of his Skewer Meal Packs, and takes out all of the contents from the chosen packs, that is, two skewers and some pieces of beef or green pepper. (Remaining Skewer Meal Packs will not be used.) Then, all those pieces of food are threaded onto both skewers, one by one, in any order.</p> <p>(See the image in the Sample section for better understanding.)</p> <p>In how many different ways can he make a Skewer Meal? Two ways of making a Skewer Meal is different if and only if the sets of the used skewers are different, or the orders of the pieces of food are different. Since this number can be extremely large, find it modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦200,000</var></li> <li><var>1≦A_i≦2000, 1≦B_i≦2000</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>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> : <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the different ways Snuke can make a serving of Skewer Meal, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 1 1 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>26 </pre> <p>The <var>26</var> ways of making a Skewer Meal are shown below. Gray bars represent skewers, each with a number denoting the Skewer Meal Set that contained the skewer. Brown and green rectangles represent pieces of beef and green pepper, respectively.</p> <div style="text-align: center;"> <img alt="ebbq.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/ebbq.png"> </img></div></section> </div> </span>
s776194541
p04051
Accepted
import numpy as np N = int(input()) A = [list(map(int, input().split())) for _ in range(N)] mod = int(1e+9) + 7 def extgcd(a, b): if b == 0: return 1, 0 else: x, y, u, v, k, l = 1, 0, 0, 1, a, b while l != 0: x, y, u, v = u, v, x - u * (k // l), y - v * (k // l) k, l = l, k % l return x, y def inved(x): a, b = extgcd(x, mod) return a % mod fact = [1 for i in range(8001)] finv = [0 for i in range(8001)] for i in range(8000): fact[i+1] = (fact[i] * (i + 1)) % mod finv[8000] = inved(fact[8000]) for i in range(8000, 0, -1): finv[i-1] = (finv[i] * i) % mod Y = 0 for i in range(N): Y += (fact[2*(A[i][0]+A[i][1])]*finv[2*A[i][0]]*finv[2*A[i][1]])%mod Y %= mod B = [[] for i in range(4001)] for i in A: B[i[0]+i[1]].append(2000-i[0]) f = np.zeros(2000+2000+1,np.int64) for b in B[::-1]: f[1:] += f[:-1].copy() np.add.at(f,b,1) f %= mod X = (f * f[::-1] % mod).sum() % mod print(((X-Y) * inved(2))%mod)
3 1 1 1 1 2 1
26
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is having another barbeque party.</p> <p>This time, he will make one serving of <em>Skewer Meal</em>.</p> <p>He has a stock of <var>N</var> <em>Skewer Meal Packs</em>. The <var>i</var>-th Skewer Meal Pack contains one skewer, <var>A_i</var> pieces of beef and <var>B_i</var> pieces of green pepper. All skewers in these packs are different and distinguishable, while all pieces of beef and all pieces of green pepper are, respectively, indistinguishable.</p> <p>To make a Skewer Meal, he chooses two of his Skewer Meal Packs, and takes out all of the contents from the chosen packs, that is, two skewers and some pieces of beef or green pepper. (Remaining Skewer Meal Packs will not be used.) Then, all those pieces of food are threaded onto both skewers, one by one, in any order.</p> <p>(See the image in the Sample section for better understanding.)</p> <p>In how many different ways can he make a Skewer Meal? Two ways of making a Skewer Meal is different if and only if the sets of the used skewers are different, or the orders of the pieces of food are different. Since this number can be extremely large, find it modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦200,000</var></li> <li><var>1≦A_i≦2000, 1≦B_i≦2000</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>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> : <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the different ways Snuke can make a serving of Skewer Meal, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 1 1 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>26 </pre> <p>The <var>26</var> ways of making a Skewer Meal are shown below. Gray bars represent skewers, each with a number denoting the Skewer Meal Set that contained the skewer. Brown and green rectangles represent pieces of beef and green pepper, respectively.</p> <div style="text-align: center;"> <img alt="ebbq.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/ebbq.png"> </img></div></section> </div> </span>
s283438001
p04051
Accepted
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np MOD = 10 ** 9 + 7 N = int(readline()) m = map(int,read().split()) AB = zip(m,m) D = 2000 U = 10 ** 4 fact = [1] * U for n in range(1,U): fact[n] = fact[n-1] * n % MOD fact_inv = [1] * U fact_inv[-1] = pow(fact[-1],MOD-2,MOD) for n in range(U-1,0,-1): fact_inv[n-1] = fact_inv[n] * n % MOD C_to_A = [[] for _ in range(D+D+1)] Y = 0 for a,b in AB: c = a+b C_to_A[c].append(D-a) Y += fact[c+c] * fact_inv[a+a] * fact_inv[b+b] Y %= MOD f = np.zeros(D+D+1,np.int64) for A in C_to_A[::-1]: f[1:] += f[:-1].copy() np.add.at(f,A,1) f %= MOD X = (f * f[::-1] % MOD).sum() % MOD answer = (X - Y) * fact_inv[2] % MOD print(answer)
3 1 1 1 1 2 1
26
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is having another barbeque party.</p> <p>This time, he will make one serving of <em>Skewer Meal</em>.</p> <p>He has a stock of <var>N</var> <em>Skewer Meal Packs</em>. The <var>i</var>-th Skewer Meal Pack contains one skewer, <var>A_i</var> pieces of beef and <var>B_i</var> pieces of green pepper. All skewers in these packs are different and distinguishable, while all pieces of beef and all pieces of green pepper are, respectively, indistinguishable.</p> <p>To make a Skewer Meal, he chooses two of his Skewer Meal Packs, and takes out all of the contents from the chosen packs, that is, two skewers and some pieces of beef or green pepper. (Remaining Skewer Meal Packs will not be used.) Then, all those pieces of food are threaded onto both skewers, one by one, in any order.</p> <p>(See the image in the Sample section for better understanding.)</p> <p>In how many different ways can he make a Skewer Meal? Two ways of making a Skewer Meal is different if and only if the sets of the used skewers are different, or the orders of the pieces of food are different. Since this number can be extremely large, find it modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦200,000</var></li> <li><var>1≦A_i≦2000, 1≦B_i≦2000</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>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> : <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the different ways Snuke can make a serving of Skewer Meal, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 1 1 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>26 </pre> <p>The <var>26</var> ways of making a Skewer Meal are shown below. Gray bars represent skewers, each with a number denoting the Skewer Meal Set that contained the skewer. Brown and green rectangles represent pieces of beef and green pepper, respectively.</p> <div style="text-align: center;"> <img alt="ebbq.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/ebbq.png"> </img></div></section> </div> </span>
s051907309
p04051
Accepted
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np MOD = 10 ** 9 + 7 N = int(readline()) m = map(int,read().split()) AB = zip(m,m) D = 2000 U = 10 ** 4 fact = [1] * U for n in range(1,U): fact[n] = fact[n-1] * n % MOD fact_inv = [1] * U fact_inv[-1] = pow(fact[-1],MOD-2,MOD) for n in range(U-1,0,-1): fact_inv[n-1] = fact_inv[n] * n % MOD C_to_A = [[] for _ in range(D+D+1)] remove = 0 for a,b in AB: c = a+b C_to_A[c].append(D-a) remove += fact[c+c] * fact_inv[a+a] * fact_inv[b+b] dp = np.zeros(D+D+1,np.int64) for A in C_to_A[::-1]: dp[1:] += dp[:-1].copy() np.add.at(dp,A,1) dp %= MOD x = (dp * dp[::-1] % MOD).sum() % MOD x -= remove % MOD x *= fact_inv[2] x %= MOD print(x)
3 1 1 1 1 2 1
26
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is having another barbeque party.</p> <p>This time, he will make one serving of <em>Skewer Meal</em>.</p> <p>He has a stock of <var>N</var> <em>Skewer Meal Packs</em>. The <var>i</var>-th Skewer Meal Pack contains one skewer, <var>A_i</var> pieces of beef and <var>B_i</var> pieces of green pepper. All skewers in these packs are different and distinguishable, while all pieces of beef and all pieces of green pepper are, respectively, indistinguishable.</p> <p>To make a Skewer Meal, he chooses two of his Skewer Meal Packs, and takes out all of the contents from the chosen packs, that is, two skewers and some pieces of beef or green pepper. (Remaining Skewer Meal Packs will not be used.) Then, all those pieces of food are threaded onto both skewers, one by one, in any order.</p> <p>(See the image in the Sample section for better understanding.)</p> <p>In how many different ways can he make a Skewer Meal? Two ways of making a Skewer Meal is different if and only if the sets of the used skewers are different, or the orders of the pieces of food are different. Since this number can be extremely large, find it modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦200,000</var></li> <li><var>1≦A_i≦2000, 1≦B_i≦2000</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>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> : <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the different ways Snuke can make a serving of Skewer Meal, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 1 1 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>26 </pre> <p>The <var>26</var> ways of making a Skewer Meal are shown below. Gray bars represent skewers, each with a number denoting the Skewer Meal Set that contained the skewer. Brown and green rectangles represent pieces of beef and green pepper, respectively.</p> <div style="text-align: center;"> <img alt="ebbq.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/ebbq.png"> </img></div></section> </div> </span>
s218722401
p04051
Accepted
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np MOD = 10 ** 9 + 7 N = int(readline()) m = map(int,read().split()) AB = zip(m,m) D = 2000 def cumprod(arr,MOD): L = len(arr); Lsq = int(L**.5+1) arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq) for n in range(1,Lsq): arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD for n in range(1,Lsq): arr[n] *= arr[n-1,-1]; arr[n] %= MOD return arr.ravel()[:L] def make_fact(U,MOD): x = np.arange(U,dtype=np.int64); x[0] = 1 fact = cumprod(x,MOD) x = np.arange(U,0,-1,dtype=np.int64); x[0] = pow(int(fact[-1]),MOD-2,MOD) fact_inv = cumprod(x,MOD)[::-1] return fact,fact_inv fact,fact_inv = make_fact(10 ** 4,MOD) fact = fact.tolist() fact_inv = fact_inv.tolist() C_to_A = [[] for _ in range(D+D+1)] remove = 0 for a,b in AB: c = a+b C_to_A[c].append(D-a) remove += fact[c+c] * fact_inv[a+a] * fact_inv[b+b] remove %= MOD dp = np.zeros(D+D+1,np.int64) for A in C_to_A[::-1]: dp[:0:-1] += dp[-2::-1] np.add.at(dp,A,1) dp %= MOD x = (dp * dp[::-1] % MOD).sum() % MOD x -= remove if x&1: x += MOD x //= 2 x %= MOD print(x)
3 1 1 1 1 2 1
26
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is having another barbeque party.</p> <p>This time, he will make one serving of <em>Skewer Meal</em>.</p> <p>He has a stock of <var>N</var> <em>Skewer Meal Packs</em>. The <var>i</var>-th Skewer Meal Pack contains one skewer, <var>A_i</var> pieces of beef and <var>B_i</var> pieces of green pepper. All skewers in these packs are different and distinguishable, while all pieces of beef and all pieces of green pepper are, respectively, indistinguishable.</p> <p>To make a Skewer Meal, he chooses two of his Skewer Meal Packs, and takes out all of the contents from the chosen packs, that is, two skewers and some pieces of beef or green pepper. (Remaining Skewer Meal Packs will not be used.) Then, all those pieces of food are threaded onto both skewers, one by one, in any order.</p> <p>(See the image in the Sample section for better understanding.)</p> <p>In how many different ways can he make a Skewer Meal? Two ways of making a Skewer Meal is different if and only if the sets of the used skewers are different, or the orders of the pieces of food are different. Since this number can be extremely large, find it modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦200,000</var></li> <li><var>1≦A_i≦2000, 1≦B_i≦2000</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>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> : <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the different ways Snuke can make a serving of Skewer Meal, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 1 1 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>26 </pre> <p>The <var>26</var> ways of making a Skewer Meal are shown below. Gray bars represent skewers, each with a number denoting the Skewer Meal Set that contained the skewer. Brown and green rectangles represent pieces of beef and green pepper, respectively.</p> <div style="text-align: center;"> <img alt="ebbq.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/ebbq.png"> </img></div></section> </div> </span>
s522586576
p04051
Accepted
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np MOD = 10 ** 9 + 7 N = int(readline()) m = map(int,read().split()) AB = zip(m,m) D = 2000 def cumprod(arr,MOD): L = len(arr); Lsq = int(L**.5+1) arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq) for n in range(1,Lsq): arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD for n in range(1,Lsq): arr[n] *= arr[n-1,-1]; arr[n] %= MOD return arr.ravel()[:L] def make_fact(U,MOD): x = np.arange(U,dtype=np.int64); x[0] = 1 fact = cumprod(x,MOD) x = np.arange(U,0,-1,dtype=np.int64); x[0] = pow(int(fact[-1]),MOD-2,MOD) fact_inv = cumprod(x,MOD)[::-1] return fact,fact_inv fact,fact_inv = make_fact(10 ** 4,MOD) fact = fact.tolist() fact_inv = fact_inv.tolist() C_to_A = [[] for _ in range(D+D+1)] remove = 0 for a,b in AB: c = a+b C_to_A[c].append(D-a) remove += fact[c+c] * fact_inv[a+a] * fact_inv[b+b] remove %= MOD dp = np.zeros(D+D+1,np.int64) for A in C_to_A[::-1]: dp[1:] += dp[:-1].copy() np.add.at(dp,A,1) dp %= MOD x = (dp * dp[::-1] % MOD).sum() % MOD x -= remove if x&1: x += MOD x //= 2 x %= MOD print(x)
3 1 1 1 1 2 1
26
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is having another barbeque party.</p> <p>This time, he will make one serving of <em>Skewer Meal</em>.</p> <p>He has a stock of <var>N</var> <em>Skewer Meal Packs</em>. The <var>i</var>-th Skewer Meal Pack contains one skewer, <var>A_i</var> pieces of beef and <var>B_i</var> pieces of green pepper. All skewers in these packs are different and distinguishable, while all pieces of beef and all pieces of green pepper are, respectively, indistinguishable.</p> <p>To make a Skewer Meal, he chooses two of his Skewer Meal Packs, and takes out all of the contents from the chosen packs, that is, two skewers and some pieces of beef or green pepper. (Remaining Skewer Meal Packs will not be used.) Then, all those pieces of food are threaded onto both skewers, one by one, in any order.</p> <p>(See the image in the Sample section for better understanding.)</p> <p>In how many different ways can he make a Skewer Meal? Two ways of making a Skewer Meal is different if and only if the sets of the used skewers are different, or the orders of the pieces of food are different. Since this number can be extremely large, find it modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦200,000</var></li> <li><var>1≦A_i≦2000, 1≦B_i≦2000</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>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> : <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the different ways Snuke can make a serving of Skewer Meal, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 1 1 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>26 </pre> <p>The <var>26</var> ways of making a Skewer Meal are shown below. Gray bars represent skewers, each with a number denoting the Skewer Meal Set that contained the skewer. Brown and green rectangles represent pieces of beef and green pepper, respectively.</p> <div style="text-align: center;"> <img alt="ebbq.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/ebbq.png"> </img></div></section> </div> </span>
s186603920
p04051
Accepted
from collections import defaultdict def solve(): Base = 2000 MAX = Base*2 p = 10**9+7 F = [1]; Finv = [0]*(MAX*2+1) for i in xrange(MAX*2): F.append(F[i]*(i+1)%p) Finv[MAX] = pow(F[MAX],p-2,p) for i in xrange(MAX,0,-1): Finv[i-1] = Finv[i]*i%p N = int(raw_input()) dup = A_MAX = B_MAX = 0 dp = [[0]*(MAX+2) for i in xrange(MAX+2)] goals = defaultdict(int) for i in xrange(N): A,B = map(int,raw_input().split()) dup = (dup + F[A*2+B*2]*Finv[A*2]*Finv[B*2])%p if A > A_MAX: A_MAX = A if B > B_MAX: B_MAX = B goals[(Base+A,Base+B)] += 1 dp[Base-B][Base-A] += 1 for j in xrange(Base-B_MAX,Base+B_MAX+1): for i in xrange(Base-A_MAX,Base+A_MAX+1): dp[j+1][i] = (dp[j+1][i] + dp[j][i]) % p dp[j][i+1] = (dp[j][i+1] + dp[j][i]) % p ans = 0 for (i,j),v in goals.iteritems(): ans = (ans + dp[j][i]*v) % p print ((ans - dup)*pow(2,p-2,p)+p) % p solve()
3 1 1 1 1 2 1
26
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is having another barbeque party.</p> <p>This time, he will make one serving of <em>Skewer Meal</em>.</p> <p>He has a stock of <var>N</var> <em>Skewer Meal Packs</em>. The <var>i</var>-th Skewer Meal Pack contains one skewer, <var>A_i</var> pieces of beef and <var>B_i</var> pieces of green pepper. All skewers in these packs are different and distinguishable, while all pieces of beef and all pieces of green pepper are, respectively, indistinguishable.</p> <p>To make a Skewer Meal, he chooses two of his Skewer Meal Packs, and takes out all of the contents from the chosen packs, that is, two skewers and some pieces of beef or green pepper. (Remaining Skewer Meal Packs will not be used.) Then, all those pieces of food are threaded onto both skewers, one by one, in any order.</p> <p>(See the image in the Sample section for better understanding.)</p> <p>In how many different ways can he make a Skewer Meal? Two ways of making a Skewer Meal is different if and only if the sets of the used skewers are different, or the orders of the pieces of food are different. Since this number can be extremely large, find it modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦200,000</var></li> <li><var>1≦A_i≦2000, 1≦B_i≦2000</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>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> : <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the different ways Snuke can make a serving of Skewer Meal, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 1 1 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>26 </pre> <p>The <var>26</var> ways of making a Skewer Meal are shown below. Gray bars represent skewers, each with a number denoting the Skewer Meal Set that contained the skewer. Brown and green rectangles represent pieces of beef and green pepper, respectively.</p> <div style="text-align: center;"> <img alt="ebbq.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/ebbq.png"> </img></div></section> </div> </span>
s482351851
p04051
Runtime Error
import math n = int(input()) list = [] for i in range(n): list.append(input().split()) sum = 0 for j in range(n): for k in range(j+1,n): if j!=k: num = math.factorial(int(list[j][0])+int(list[j][1])+int(list[k][0])+int(list[k][1])) / (math.factorial(int(list[j][0])+int(list[k][0]))*math.factorial(int(list[j][1])+int(list[k][1]))) sum += num print(int(sum%(10**9+7)))
3 1 1 1 1 2 1
26
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is having another barbeque party.</p> <p>This time, he will make one serving of <em>Skewer Meal</em>.</p> <p>He has a stock of <var>N</var> <em>Skewer Meal Packs</em>. The <var>i</var>-th Skewer Meal Pack contains one skewer, <var>A_i</var> pieces of beef and <var>B_i</var> pieces of green pepper. All skewers in these packs are different and distinguishable, while all pieces of beef and all pieces of green pepper are, respectively, indistinguishable.</p> <p>To make a Skewer Meal, he chooses two of his Skewer Meal Packs, and takes out all of the contents from the chosen packs, that is, two skewers and some pieces of beef or green pepper. (Remaining Skewer Meal Packs will not be used.) Then, all those pieces of food are threaded onto both skewers, one by one, in any order.</p> <p>(See the image in the Sample section for better understanding.)</p> <p>In how many different ways can he make a Skewer Meal? Two ways of making a Skewer Meal is different if and only if the sets of the used skewers are different, or the orders of the pieces of food are different. Since this number can be extremely large, find it modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦200,000</var></li> <li><var>1≦A_i≦2000, 1≦B_i≦2000</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>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> : <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the different ways Snuke can make a serving of Skewer Meal, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 1 1 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>26 </pre> <p>The <var>26</var> ways of making a Skewer Meal are shown below. Gray bars represent skewers, each with a number denoting the Skewer Meal Set that contained the skewer. Brown and green rectangles represent pieces of beef and green pepper, respectively.</p> <div style="text-align: center;"> <img alt="ebbq.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/ebbq.png"> </img></div></section> </div> </span>
s525778405
p04051
Runtime Error
#include<bits/stdc++.h> using namespace std; const int N=2e5+50,M=4040,mod=1e9+7,L=2000; int n,a[N],b[N],f[M][M],ans,J[N],I[N]; int C(int n,int m){return 1ll*J[n]*I[m]%mod*I[n-m]%mod;} int main(){ scanf("%d",&n);J[0]=I[0]=I[1]=1; for(int i=2;i<=4*L;i++)I[i]=mod-1ll*mod/i*I[mod%i]%mod; for(int i=1;i<=4*L;i++)J[i]=1ll*J[i-1]*i%mod,I[i]=1ll*I[i-1]*I[i]%mod; for(int i=1;i<=n;i++)scanf("%d%d",&a[i],&b[i]); for(int i=1;i<=n;i++)f[L-a[i]][L-b[i]]++; for(int i=0;i<=2*L;i++)for(int j=0;j<=2*L;j++){ if(i)(f[i][j]+=f[i-1][j])%=mod; if(j)(f[i][j]+=f[i][j-1])%=mod; } for(int i=1;i<=n;i++)(ans+=f[L+a[i]][L+b[i]]-C(2*(a[i]+b[i]),2*a[i]))%=mod; printf("%d\n",1ll*ans*I[2]%mod); return 0; }
3 1 1 1 1 2 1
26
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is having another barbeque party.</p> <p>This time, he will make one serving of <em>Skewer Meal</em>.</p> <p>He has a stock of <var>N</var> <em>Skewer Meal Packs</em>. The <var>i</var>-th Skewer Meal Pack contains one skewer, <var>A_i</var> pieces of beef and <var>B_i</var> pieces of green pepper. All skewers in these packs are different and distinguishable, while all pieces of beef and all pieces of green pepper are, respectively, indistinguishable.</p> <p>To make a Skewer Meal, he chooses two of his Skewer Meal Packs, and takes out all of the contents from the chosen packs, that is, two skewers and some pieces of beef or green pepper. (Remaining Skewer Meal Packs will not be used.) Then, all those pieces of food are threaded onto both skewers, one by one, in any order.</p> <p>(See the image in the Sample section for better understanding.)</p> <p>In how many different ways can he make a Skewer Meal? Two ways of making a Skewer Meal is different if and only if the sets of the used skewers are different, or the orders of the pieces of food are different. Since this number can be extremely large, find it modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦200,000</var></li> <li><var>1≦A_i≦2000, 1≦B_i≦2000</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>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> : <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the different ways Snuke can make a serving of Skewer Meal, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 1 1 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>26 </pre> <p>The <var>26</var> ways of making a Skewer Meal are shown below. Gray bars represent skewers, each with a number denoting the Skewer Meal Set that contained the skewer. Brown and green rectangles represent pieces of beef and green pepper, respectively.</p> <div style="text-align: center;"> <img alt="ebbq.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/ebbq.png"> </img></div></section> </div> </span>
s389585547
p04051
Runtime Error
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np MOD = 10 ** 9 + 7 N = int(readline()) m = map(int,read().split()) AB = zip(m,m) D = 2000 def cumprod(arr,MOD): L = len(arr); Lsq = int(L**.5+1) arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq) for n in range(1,Lsq): arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD for n in range(1,Lsq): arr[n] *= arr[n-1,-1]; arr[n] %= MOD return arr.ravel()[:L] def make_fact(U,MOD): x = np.arange(U,dtype=np.int64); x[0] = 1 fact = cumprod(x,MOD) x = np.arange(U,0,-1,dtype=np.int64); x[0] = pow(int(fact[-1]),MOD-2,MOD) fact_inv = cumprod(x,MOD)[::-1] return fact,fact_inv fact,fact_inv = make_fact(10 ** 4,MOD) fact = fact.tolist() fact_inv = fact_inv.tolist() C_to_A = [[] for _ in range(D+D+1)] remove = 0 for a,b in AB: c = a+b C_to_A[c].append(D-a) remove += fact[c+c] * fact_inv[a+a] * fact_inv[b+b] remove %= MOD dp = np.zeros(D+D+1,np.int64) for A in C_to_A[::-1]: dp[:0:-1] += dp[-1::-1] np.add.at(dp,A,1) dp %= MOD x = (dp * dp[::-1] % MOD).sum() % MOD x -= remove if x&1: x += MOD x //= 2 x %= MOD print(x)
3 1 1 1 1 2 1
26
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is having another barbeque party.</p> <p>This time, he will make one serving of <em>Skewer Meal</em>.</p> <p>He has a stock of <var>N</var> <em>Skewer Meal Packs</em>. The <var>i</var>-th Skewer Meal Pack contains one skewer, <var>A_i</var> pieces of beef and <var>B_i</var> pieces of green pepper. All skewers in these packs are different and distinguishable, while all pieces of beef and all pieces of green pepper are, respectively, indistinguishable.</p> <p>To make a Skewer Meal, he chooses two of his Skewer Meal Packs, and takes out all of the contents from the chosen packs, that is, two skewers and some pieces of beef or green pepper. (Remaining Skewer Meal Packs will not be used.) Then, all those pieces of food are threaded onto both skewers, one by one, in any order.</p> <p>(See the image in the Sample section for better understanding.)</p> <p>In how many different ways can he make a Skewer Meal? Two ways of making a Skewer Meal is different if and only if the sets of the used skewers are different, or the orders of the pieces of food are different. Since this number can be extremely large, find it modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦200,000</var></li> <li><var>1≦A_i≦2000, 1≦B_i≦2000</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>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> : <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the different ways Snuke can make a serving of Skewer Meal, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 1 1 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>26 </pre> <p>The <var>26</var> ways of making a Skewer Meal are shown below. Gray bars represent skewers, each with a number denoting the Skewer Meal Set that contained the skewer. Brown and green rectangles represent pieces of beef and green pepper, respectively.</p> <div style="text-align: center;"> <img alt="ebbq.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/ebbq.png"> </img></div></section> </div> </span>
s797478744
p04051
Runtime Error
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np MOD = 10 ** 9 + 7 N = int(readline()) m = map(int,read().split()) AB = zip(m,m) D = 2000 def cumprod(arr,MOD): L = len(arr); Lsq = int(L**.5+1) arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq) for n in range(1,Lsq): arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD for n in range(1,Lsq): arr[n] *= arr[n-1,-1]; arr[n] %= MOD return arr.ravel()[:L] def make_fact(U,MOD): x = np.arange(U,dtype=np.int64); x[0] = 1 fact = cumprod(x,MOD) x = np.arange(U,0,-1,dtype=np.int64); x[0] = pow(int(fact[-1]),MOD-2,MOD) fact_inv = cumprod(x,MOD)[::-1] return fact,fact_inv fact,fact_inv = make_fact(D+D+100,MOD) fact = fact.tolist() fact_inv = fact_inv.tolist() C_to_A = [[] for _ in range(D+D+1)] remove = 0 for a,b in AB: c = a+b C_to_A[c].append(D-a) remove += fact[c+c] * fact_inv[a+a] * fact_inv[b+b] remove %= MOD dp = np.zeros(D+D+1,np.int64) for A in C_to_A[::-1]: dp[1:] += dp[:-1] np.add.at(dp,A,1) x = (dp * dp[::-1] % MOD).sum() % MOD x -= remove if x&1: x += MOD x //= 2 x %= MOD print(x)
3 1 1 1 1 2 1
26
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is having another barbeque party.</p> <p>This time, he will make one serving of <em>Skewer Meal</em>.</p> <p>He has a stock of <var>N</var> <em>Skewer Meal Packs</em>. The <var>i</var>-th Skewer Meal Pack contains one skewer, <var>A_i</var> pieces of beef and <var>B_i</var> pieces of green pepper. All skewers in these packs are different and distinguishable, while all pieces of beef and all pieces of green pepper are, respectively, indistinguishable.</p> <p>To make a Skewer Meal, he chooses two of his Skewer Meal Packs, and takes out all of the contents from the chosen packs, that is, two skewers and some pieces of beef or green pepper. (Remaining Skewer Meal Packs will not be used.) Then, all those pieces of food are threaded onto both skewers, one by one, in any order.</p> <p>(See the image in the Sample section for better understanding.)</p> <p>In how many different ways can he make a Skewer Meal? Two ways of making a Skewer Meal is different if and only if the sets of the used skewers are different, or the orders of the pieces of food are different. Since this number can be extremely large, find it modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦200,000</var></li> <li><var>1≦A_i≦2000, 1≦B_i≦2000</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>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> : <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the different ways Snuke can make a serving of Skewer Meal, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 1 1 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>26 </pre> <p>The <var>26</var> ways of making a Skewer Meal are shown below. Gray bars represent skewers, each with a number denoting the Skewer Meal Set that contained the skewer. Brown and green rectangles represent pieces of beef and green pepper, respectively.</p> <div style="text-align: center;"> <img alt="ebbq.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/ebbq.png"> </img></div></section> </div> </span>
s089948526
p04051
Runtime Error
def co(a, b): a += b res = 1 for i in range(1,b+1): res *= ((a-i+1) / i) return int(res) n = int(input()) a = [0 for i in range(n)] b = [0 for i in range(n)] for ni in range(n): a[ni], b[ni] = (int(i) for i in input().split(" ")) a = tuple(a) b = tuple(b) res = 0 for i in range(n): for j in range(i+1,n): res += co(a[i]+a[j], b[i]+b[j]) res %= (10**9+7) print(res)
3 1 1 1 1 2 1
26
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is having another barbeque party.</p> <p>This time, he will make one serving of <em>Skewer Meal</em>.</p> <p>He has a stock of <var>N</var> <em>Skewer Meal Packs</em>. The <var>i</var>-th Skewer Meal Pack contains one skewer, <var>A_i</var> pieces of beef and <var>B_i</var> pieces of green pepper. All skewers in these packs are different and distinguishable, while all pieces of beef and all pieces of green pepper are, respectively, indistinguishable.</p> <p>To make a Skewer Meal, he chooses two of his Skewer Meal Packs, and takes out all of the contents from the chosen packs, that is, two skewers and some pieces of beef or green pepper. (Remaining Skewer Meal Packs will not be used.) Then, all those pieces of food are threaded onto both skewers, one by one, in any order.</p> <p>(See the image in the Sample section for better understanding.)</p> <p>In how many different ways can he make a Skewer Meal? Two ways of making a Skewer Meal is different if and only if the sets of the used skewers are different, or the orders of the pieces of food are different. Since this number can be extremely large, find it modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦200,000</var></li> <li><var>1≦A_i≦2000, 1≦B_i≦2000</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>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> : <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the different ways Snuke can make a serving of Skewer Meal, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 1 1 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>26 </pre> <p>The <var>26</var> ways of making a Skewer Meal are shown below. Gray bars represent skewers, each with a number denoting the Skewer Meal Set that contained the skewer. Brown and green rectangles represent pieces of beef and green pepper, respectively.</p> <div style="text-align: center;"> <img alt="ebbq.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/ebbq.png"> </img></div></section> </div> </span>
s293146402
p04051
Runtime Error
def co(a, b): a += b res = 1 for i in range(1,b+1): res *= ((a-i+1) / i) return int(res) n = int(input()) a = [0 for i in range(n)] b = [0 for i in range(n)] for ni in range(n): a[ni], b[ni] = (int(i) for i in input().split(" ")) res = 0 for i in range(n): for j in range(i+1,n): res += co(a[i]+a[j], b[i]+b[j]) res %= 10**9+7 print(res)
3 1 1 1 1 2 1
26
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is having another barbeque party.</p> <p>This time, he will make one serving of <em>Skewer Meal</em>.</p> <p>He has a stock of <var>N</var> <em>Skewer Meal Packs</em>. The <var>i</var>-th Skewer Meal Pack contains one skewer, <var>A_i</var> pieces of beef and <var>B_i</var> pieces of green pepper. All skewers in these packs are different and distinguishable, while all pieces of beef and all pieces of green pepper are, respectively, indistinguishable.</p> <p>To make a Skewer Meal, he chooses two of his Skewer Meal Packs, and takes out all of the contents from the chosen packs, that is, two skewers and some pieces of beef or green pepper. (Remaining Skewer Meal Packs will not be used.) Then, all those pieces of food are threaded onto both skewers, one by one, in any order.</p> <p>(See the image in the Sample section for better understanding.)</p> <p>In how many different ways can he make a Skewer Meal? Two ways of making a Skewer Meal is different if and only if the sets of the used skewers are different, or the orders of the pieces of food are different. Since this number can be extremely large, find it modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦200,000</var></li> <li><var>1≦A_i≦2000, 1≦B_i≦2000</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>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> : <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the different ways Snuke can make a serving of Skewer Meal, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 1 1 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>26 </pre> <p>The <var>26</var> ways of making a Skewer Meal are shown below. Gray bars represent skewers, each with a number denoting the Skewer Meal Set that contained the skewer. Brown and green rectangles represent pieces of beef and green pepper, respectively.</p> <div style="text-align: center;"> <img alt="ebbq.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/ebbq.png"> </img></div></section> </div> </span>
s140871420
p04051
Runtime Error
def co(a, b): res = 1 for i in range(1,b+1): res *= ((a-i+1) / i) return int(res) n = int(input()) a = [0 for i in range(n)] b = [0 for i in range(n)] for ni in range(n): a[ni], b[ni] = (int(i) for i in input().split(" ")) res = 0 for i in range(n): for j in range(i+1,n): res += co(a[i]+a[j]+b[i]+b[j], b[i]+b[j]) print(res % (10**9+7))
3 1 1 1 1 2 1
26
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is having another barbeque party.</p> <p>This time, he will make one serving of <em>Skewer Meal</em>.</p> <p>He has a stock of <var>N</var> <em>Skewer Meal Packs</em>. The <var>i</var>-th Skewer Meal Pack contains one skewer, <var>A_i</var> pieces of beef and <var>B_i</var> pieces of green pepper. All skewers in these packs are different and distinguishable, while all pieces of beef and all pieces of green pepper are, respectively, indistinguishable.</p> <p>To make a Skewer Meal, he chooses two of his Skewer Meal Packs, and takes out all of the contents from the chosen packs, that is, two skewers and some pieces of beef or green pepper. (Remaining Skewer Meal Packs will not be used.) Then, all those pieces of food are threaded onto both skewers, one by one, in any order.</p> <p>(See the image in the Sample section for better understanding.)</p> <p>In how many different ways can he make a Skewer Meal? Two ways of making a Skewer Meal is different if and only if the sets of the used skewers are different, or the orders of the pieces of food are different. Since this number can be extremely large, find it modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦200,000</var></li> <li><var>1≦A_i≦2000, 1≦B_i≦2000</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>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> : <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the different ways Snuke can make a serving of Skewer Meal, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 1 1 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>26 </pre> <p>The <var>26</var> ways of making a Skewer Meal are shown below. Gray bars represent skewers, each with a number denoting the Skewer Meal Set that contained the skewer. Brown and green rectangles represent pieces of beef and green pepper, respectively.</p> <div style="text-align: center;"> <img alt="ebbq.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/ebbq.png"> </img></div></section> </div> </span>
s200518468
p04051
Runtime Error
# your code goes here from itertools import combinations from scipy.misc import comb N = int(input()) A = [] B = [] for n in range(N): a, b = [int(x) for x in input().split()] A.append(a) B.append(b) S = 0 for n1, n2 in combinations(range(N),2): a1, b1 = A[n1], B[n1] a2, b2 = A[n2], B[n2] s = comb(a1+b1+a2+b2, a1+a2, exact=True) S += s % (1e+9 + 7) S %= 1e+9+7 print(int(S))
3 1 1 1 1 2 1
26
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is having another barbeque party.</p> <p>This time, he will make one serving of <em>Skewer Meal</em>.</p> <p>He has a stock of <var>N</var> <em>Skewer Meal Packs</em>. The <var>i</var>-th Skewer Meal Pack contains one skewer, <var>A_i</var> pieces of beef and <var>B_i</var> pieces of green pepper. All skewers in these packs are different and distinguishable, while all pieces of beef and all pieces of green pepper are, respectively, indistinguishable.</p> <p>To make a Skewer Meal, he chooses two of his Skewer Meal Packs, and takes out all of the contents from the chosen packs, that is, two skewers and some pieces of beef or green pepper. (Remaining Skewer Meal Packs will not be used.) Then, all those pieces of food are threaded onto both skewers, one by one, in any order.</p> <p>(See the image in the Sample section for better understanding.)</p> <p>In how many different ways can he make a Skewer Meal? Two ways of making a Skewer Meal is different if and only if the sets of the used skewers are different, or the orders of the pieces of food are different. Since this number can be extremely large, find it modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦200,000</var></li> <li><var>1≦A_i≦2000, 1≦B_i≦2000</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>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> : <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the different ways Snuke can make a serving of Skewer Meal, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 1 1 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>26 </pre> <p>The <var>26</var> ways of making a Skewer Meal are shown below. Gray bars represent skewers, each with a number denoting the Skewer Meal Set that contained the skewer. Brown and green rectangles represent pieces of beef and green pepper, respectively.</p> <div style="text-align: center;"> <img alt="ebbq.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/ebbq.png"> </img></div></section> </div> </span>
s350121004
p04051
Runtime Error
# your code goes here from itertools import combinations from scipy.special import comb # a = comb(n, r) # a = comb(n, r, exact=True) N = int(input()) A = [] B = [] for n in range(N): a, b = [int(x) for x in input().split()] A.append(a) B.append(b) S = 0 for n1, n2 in combinations(range(N),2): a1, b1 = A[n1], B[n1] a2, b2 = A[n2], B[n2] s = comb(a1+b1+a2+b2, a1+a2, exact=True) S += s % (1e+9 + 7) S %= 1e+9+7 print(int(S))
3 1 1 1 1 2 1
26
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is having another barbeque party.</p> <p>This time, he will make one serving of <em>Skewer Meal</em>.</p> <p>He has a stock of <var>N</var> <em>Skewer Meal Packs</em>. The <var>i</var>-th Skewer Meal Pack contains one skewer, <var>A_i</var> pieces of beef and <var>B_i</var> pieces of green pepper. All skewers in these packs are different and distinguishable, while all pieces of beef and all pieces of green pepper are, respectively, indistinguishable.</p> <p>To make a Skewer Meal, he chooses two of his Skewer Meal Packs, and takes out all of the contents from the chosen packs, that is, two skewers and some pieces of beef or green pepper. (Remaining Skewer Meal Packs will not be used.) Then, all those pieces of food are threaded onto both skewers, one by one, in any order.</p> <p>(See the image in the Sample section for better understanding.)</p> <p>In how many different ways can he make a Skewer Meal? Two ways of making a Skewer Meal is different if and only if the sets of the used skewers are different, or the orders of the pieces of food are different. Since this number can be extremely large, find it modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦200,000</var></li> <li><var>1≦A_i≦2000, 1≦B_i≦2000</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>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> : <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the different ways Snuke can make a serving of Skewer Meal, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 1 1 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>26 </pre> <p>The <var>26</var> ways of making a Skewer Meal are shown below. Gray bars represent skewers, each with a number denoting the Skewer Meal Set that contained the skewer. Brown and green rectangles represent pieces of beef and green pepper, respectively.</p> <div style="text-align: center;"> <img alt="ebbq.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/ebbq.png"> </img></div></section> </div> </span>
s504475340
p04051
Runtime Error
def fact(n): ret = 1 for i in range(2, n+1): ret *= i return ret def C(a,b,c): ret = 1 for i in range(b+1, a + 1): ret *= i return int(ret / fact(c)) n = int(input()) gu = [] for i in range(n): gu.append(list(map(int, input().split(' ')))) ret = 0 for i in range(n - 1): for j in range(i+1, n): ret += C(gu[i][0] + gu[i][1] + gu[j][0] + gu[j][1], gu[i][0] + gu[j][0], gu[i][1] + gu[j][1]) print(ret)
3 1 1 1 1 2 1
26
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is having another barbeque party.</p> <p>This time, he will make one serving of <em>Skewer Meal</em>.</p> <p>He has a stock of <var>N</var> <em>Skewer Meal Packs</em>. The <var>i</var>-th Skewer Meal Pack contains one skewer, <var>A_i</var> pieces of beef and <var>B_i</var> pieces of green pepper. All skewers in these packs are different and distinguishable, while all pieces of beef and all pieces of green pepper are, respectively, indistinguishable.</p> <p>To make a Skewer Meal, he chooses two of his Skewer Meal Packs, and takes out all of the contents from the chosen packs, that is, two skewers and some pieces of beef or green pepper. (Remaining Skewer Meal Packs will not be used.) Then, all those pieces of food are threaded onto both skewers, one by one, in any order.</p> <p>(See the image in the Sample section for better understanding.)</p> <p>In how many different ways can he make a Skewer Meal? Two ways of making a Skewer Meal is different if and only if the sets of the used skewers are different, or the orders of the pieces of food are different. Since this number can be extremely large, find it modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦200,000</var></li> <li><var>1≦A_i≦2000, 1≦B_i≦2000</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>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> : <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the different ways Snuke can make a serving of Skewer Meal, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 1 1 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>26 </pre> <p>The <var>26</var> ways of making a Skewer Meal are shown below. Gray bars represent skewers, each with a number denoting the Skewer Meal Set that contained the skewer. Brown and green rectangles represent pieces of beef and green pepper, respectively.</p> <div style="text-align: center;"> <img alt="ebbq.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/ebbq.png"> </img></div></section> </div> </span>
s917522426
p04051
Runtime Error
def fact(n): ret = 1 for i in range(2, n+1): ret *= i return ret def C(a,b,c): ret = 1 for i in range(b+1, a + 1): ret *= i return int(ret / fact(c)) n = int(input()) gu = [] for i in range(n): gu.append(list(map(int, input().split(' ')))) ret = 0 for i in range(n - 1): for j in range(i+1, n): ret += C(gu[i][0] + gu[i][1] + gu[j][0] + gu[j][1], gu[i][0] + gu[j][0], gu[i][1] + gu[j][1]) print(ret)
3 1 1 1 1 2 1
26
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is having another barbeque party.</p> <p>This time, he will make one serving of <em>Skewer Meal</em>.</p> <p>He has a stock of <var>N</var> <em>Skewer Meal Packs</em>. The <var>i</var>-th Skewer Meal Pack contains one skewer, <var>A_i</var> pieces of beef and <var>B_i</var> pieces of green pepper. All skewers in these packs are different and distinguishable, while all pieces of beef and all pieces of green pepper are, respectively, indistinguishable.</p> <p>To make a Skewer Meal, he chooses two of his Skewer Meal Packs, and takes out all of the contents from the chosen packs, that is, two skewers and some pieces of beef or green pepper. (Remaining Skewer Meal Packs will not be used.) Then, all those pieces of food are threaded onto both skewers, one by one, in any order.</p> <p>(See the image in the Sample section for better understanding.)</p> <p>In how many different ways can he make a Skewer Meal? Two ways of making a Skewer Meal is different if and only if the sets of the used skewers are different, or the orders of the pieces of food are different. Since this number can be extremely large, find it modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦200,000</var></li> <li><var>1≦A_i≦2000, 1≦B_i≦2000</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>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> : <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the different ways Snuke can make a serving of Skewer Meal, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 1 1 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>26 </pre> <p>The <var>26</var> ways of making a Skewer Meal are shown below. Gray bars represent skewers, each with a number denoting the Skewer Meal Set that contained the skewer. Brown and green rectangles represent pieces of beef and green pepper, respectively.</p> <div style="text-align: center;"> <img alt="ebbq.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/ebbq.png"> </img></div></section> </div> </span>
s853958902
p04051
Runtime Error
def fact(n): ret = 1 for i in range(2, n+1): ret *= i return ret n = int(input()) gu = [] for i in range(n): gu.append(list(map(int, input().split(' ')))) ret = 0 for i in range(n - 1): for j in range(i+1, n): ret += int(fact(gu[i][0] + gu[i][1] + gu[j][0] + gu[j][1]) / fact(gu[i][0] + gu[j][0]) / fact(gu[i][1] + gu[j][1])) print(ret)
3 1 1 1 1 2 1
26
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is having another barbeque party.</p> <p>This time, he will make one serving of <em>Skewer Meal</em>.</p> <p>He has a stock of <var>N</var> <em>Skewer Meal Packs</em>. The <var>i</var>-th Skewer Meal Pack contains one skewer, <var>A_i</var> pieces of beef and <var>B_i</var> pieces of green pepper. All skewers in these packs are different and distinguishable, while all pieces of beef and all pieces of green pepper are, respectively, indistinguishable.</p> <p>To make a Skewer Meal, he chooses two of his Skewer Meal Packs, and takes out all of the contents from the chosen packs, that is, two skewers and some pieces of beef or green pepper. (Remaining Skewer Meal Packs will not be used.) Then, all those pieces of food are threaded onto both skewers, one by one, in any order.</p> <p>(See the image in the Sample section for better understanding.)</p> <p>In how many different ways can he make a Skewer Meal? Two ways of making a Skewer Meal is different if and only if the sets of the used skewers are different, or the orders of the pieces of food are different. Since this number can be extremely large, find it modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦200,000</var></li> <li><var>1≦A_i≦2000, 1≦B_i≦2000</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>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> : <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the different ways Snuke can make a serving of Skewer Meal, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 1 1 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>26 </pre> <p>The <var>26</var> ways of making a Skewer Meal are shown below. Gray bars represent skewers, each with a number denoting the Skewer Meal Set that contained the skewer. Brown and green rectangles represent pieces of beef and green pepper, respectively.</p> <div style="text-align: center;"> <img alt="ebbq.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/ebbq.png"> </img></div></section> </div> </span>
s608875432
p04051
Runtime Error
def fact(n): if n == 1: return 1 else: return fact(n - 1) * n n = int(input()) gu = [] for i in range(n): gu.append(list(map(int, input().split(' ')))) ret = 0 for i in range(n - 1): for j in range(i+1, n): ret += int(fact(gu[i][0] + gu[i][1] + gu[j][0] + gu[j][1]) / fact(gu[i][0] + gu[j][0]) / fact(gu[i][1] + gu[j][1])) print(ret)
3 1 1 1 1 2 1
26
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is having another barbeque party.</p> <p>This time, he will make one serving of <em>Skewer Meal</em>.</p> <p>He has a stock of <var>N</var> <em>Skewer Meal Packs</em>. The <var>i</var>-th Skewer Meal Pack contains one skewer, <var>A_i</var> pieces of beef and <var>B_i</var> pieces of green pepper. All skewers in these packs are different and distinguishable, while all pieces of beef and all pieces of green pepper are, respectively, indistinguishable.</p> <p>To make a Skewer Meal, he chooses two of his Skewer Meal Packs, and takes out all of the contents from the chosen packs, that is, two skewers and some pieces of beef or green pepper. (Remaining Skewer Meal Packs will not be used.) Then, all those pieces of food are threaded onto both skewers, one by one, in any order.</p> <p>(See the image in the Sample section for better understanding.)</p> <p>In how many different ways can he make a Skewer Meal? Two ways of making a Skewer Meal is different if and only if the sets of the used skewers are different, or the orders of the pieces of food are different. Since this number can be extremely large, find it modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦200,000</var></li> <li><var>1≦A_i≦2000, 1≦B_i≦2000</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>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> : <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the different ways Snuke can make a serving of Skewer Meal, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 1 1 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>26 </pre> <p>The <var>26</var> ways of making a Skewer Meal are shown below. Gray bars represent skewers, each with a number denoting the Skewer Meal Set that contained the skewer. Brown and green rectangles represent pieces of beef and green pepper, respectively.</p> <div style="text-align: center;"> <img alt="ebbq.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/ebbq.png"> </img></div></section> </div> </span>
s741244779
p04051
Runtime Error
import scipy.misc as scm def combi(p,q): return scm.comb(p,q,1) ans=0 n=int(input()) k=[] for i in range(n): a,b=map(int,input().split()) k.append([a,b]) for i in range(n-1): for j in range(1,n): p=k[i][0]+k[i][1]+k[j][0]+k[j][1] q=k[i][0]+k[j][0] ans += combi(p,q) % (10**9+7) print(ans)
3 1 1 1 1 2 1
26
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is having another barbeque party.</p> <p>This time, he will make one serving of <em>Skewer Meal</em>.</p> <p>He has a stock of <var>N</var> <em>Skewer Meal Packs</em>. The <var>i</var>-th Skewer Meal Pack contains one skewer, <var>A_i</var> pieces of beef and <var>B_i</var> pieces of green pepper. All skewers in these packs are different and distinguishable, while all pieces of beef and all pieces of green pepper are, respectively, indistinguishable.</p> <p>To make a Skewer Meal, he chooses two of his Skewer Meal Packs, and takes out all of the contents from the chosen packs, that is, two skewers and some pieces of beef or green pepper. (Remaining Skewer Meal Packs will not be used.) Then, all those pieces of food are threaded onto both skewers, one by one, in any order.</p> <p>(See the image in the Sample section for better understanding.)</p> <p>In how many different ways can he make a Skewer Meal? Two ways of making a Skewer Meal is different if and only if the sets of the used skewers are different, or the orders of the pieces of food are different. Since this number can be extremely large, find it modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦200,000</var></li> <li><var>1≦A_i≦2000, 1≦B_i≦2000</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>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> : <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the different ways Snuke can make a serving of Skewer Meal, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 1 1 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>26 </pre> <p>The <var>26</var> ways of making a Skewer Meal are shown below. Gray bars represent skewers, each with a number denoting the Skewer Meal Set that contained the skewer. Brown and green rectangles represent pieces of beef and green pepper, respectively.</p> <div style="text-align: center;"> <img alt="ebbq.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/ebbq.png"> </img></div></section> </div> </span>
s510438237
p04051
Runtime Error
def calc(ab1,ab2): meat = ab1[0] + ab2[0] vege = ab1[1] + ab2[1] pattern = fact_list[meat+vege] / (fact_list[meat] * fact_list[vege]) return pattern if __name__ == '__main__': N = int(input()) AB = [list(map(int, input().split())) for i in range(N)] fact_list = {} fact_list[0] = 1 max_ab = max(AB[x][0] + AB[x][1] for x in range(N)) for i in range(1,2*max_ab): fact_list[i] = fact_list[i-1] * i sum_count = 0 for i in range(N): for j in range(i+1,N): sum_count += calc(AB[i],AB[j]) print( int(sum_count % (10**9 + 7)) )
3 1 1 1 1 2 1
26
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is having another barbeque party.</p> <p>This time, he will make one serving of <em>Skewer Meal</em>.</p> <p>He has a stock of <var>N</var> <em>Skewer Meal Packs</em>. The <var>i</var>-th Skewer Meal Pack contains one skewer, <var>A_i</var> pieces of beef and <var>B_i</var> pieces of green pepper. All skewers in these packs are different and distinguishable, while all pieces of beef and all pieces of green pepper are, respectively, indistinguishable.</p> <p>To make a Skewer Meal, he chooses two of his Skewer Meal Packs, and takes out all of the contents from the chosen packs, that is, two skewers and some pieces of beef or green pepper. (Remaining Skewer Meal Packs will not be used.) Then, all those pieces of food are threaded onto both skewers, one by one, in any order.</p> <p>(See the image in the Sample section for better understanding.)</p> <p>In how many different ways can he make a Skewer Meal? Two ways of making a Skewer Meal is different if and only if the sets of the used skewers are different, or the orders of the pieces of food are different. Since this number can be extremely large, find it modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦200,000</var></li> <li><var>1≦A_i≦2000, 1≦B_i≦2000</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>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> : <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the different ways Snuke can make a serving of Skewer Meal, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 1 1 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>26 </pre> <p>The <var>26</var> ways of making a Skewer Meal are shown below. Gray bars represent skewers, each with a number denoting the Skewer Meal Set that contained the skewer. Brown and green rectangles represent pieces of beef and green pepper, respectively.</p> <div style="text-align: center;"> <img alt="ebbq.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/ebbq.png"> </img></div></section> </div> </span>
s959683316
p04051
Runtime Error
def calc(ab1,ab2,fact_list): meat = ab1[0] + ab2[0] vege = ab1[1] + ab2[1] pattern = fact_list[meat+vege] / (fact_list[meat] * fact_list[vege]) return pattern if __name__ == '__main__': N = int(input()) AB = [list(map(int, input().split())) for i in range(N)] fact_list = {} fact_list[0] = 1 max_ab = max(AB[x][0] + AB[x][1] for x in range(N)) for i in range(1,2*max_ab): fact_list[i] = fact_list[i-1] * i sum_count = 0 for i in range(N): for j in range(i+1,N): sum_count += calc(AB[i],AB[j],fact_list) print( int(sum_count % (10**9 + 7)) )
3 1 1 1 1 2 1
26
<span class="lang-en"> <p>Score : <var>1400</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>Snuke is having another barbeque party.</p> <p>This time, he will make one serving of <em>Skewer Meal</em>.</p> <p>He has a stock of <var>N</var> <em>Skewer Meal Packs</em>. The <var>i</var>-th Skewer Meal Pack contains one skewer, <var>A_i</var> pieces of beef and <var>B_i</var> pieces of green pepper. All skewers in these packs are different and distinguishable, while all pieces of beef and all pieces of green pepper are, respectively, indistinguishable.</p> <p>To make a Skewer Meal, he chooses two of his Skewer Meal Packs, and takes out all of the contents from the chosen packs, that is, two skewers and some pieces of beef or green pepper. (Remaining Skewer Meal Packs will not be used.) Then, all those pieces of food are threaded onto both skewers, one by one, in any order.</p> <p>(See the image in the Sample section for better understanding.)</p> <p>In how many different ways can he make a Skewer Meal? Two ways of making a Skewer Meal is different if and only if the sets of the used skewers are different, or the orders of the pieces of food are different. Since this number can be extremely large, find it modulo <var>10^9+7</var>.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦200,000</var></li> <li><var>1≦A_i≦2000, 1≦B_i≦2000</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>A_1</var> <var>B_1</var> <var>A_2</var> <var>B_2</var> : <var>A_N</var> <var>B_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the number of the different ways Snuke can make a serving of Skewer Meal, modulo <var>10^9+7</var>.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>3 1 1 1 1 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>26 </pre> <p>The <var>26</var> ways of making a Skewer Meal are shown below. Gray bars represent skewers, each with a number denoting the Skewer Meal Set that contained the skewer. Brown and green rectangles represent pieces of beef and green pepper, respectively.</p> <div style="text-align: center;"> <img alt="ebbq.png" src="https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/ebbq.png"> </img></div></section> </div> </span>
s947077253
p04052
Wrong Answer
n, k = map(int, input().split()) nums = list(map(int, input().split())) dict_indexs = {} for i, num in enumerate(nums): dict_indexs[num - 1] = i while True: flag = False for i in range(n - 1): a = dict_indexs[i] b = dict_indexs[i + 1] if a - b >= k: dict_indexs[i] = b dict_indexs[i + 1] = a flag = True if flag: continue else: break for i in range(n): print(dict_indexs[i]+1)
4 2 4 2 3 1
2 1 4 3
<span class="lang-en"> <p>Score : <var>2000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a permutation <var>P_1 ... P_N</var> of the set {<var>1</var>, <var>2</var>, ..., <var>N</var>}.</p> <p>You can apply the following operation to this permutation, any number of times (possibly zero):</p> <ul> <li>Choose two indices <var>i,j (1 ≦ i &lt; j ≦ N)</var>, such that <var>j - i ≧ K</var> and <var>|P_i - P_j| = 1</var>. Then, swap the values of <var>P_i</var> and <var>P_j</var>.</li> </ul> <p>Among all permutations that can be obtained by applying this operation to the given permutation, find the lexicographically smallest one.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦500,000</var></li> <li><var>1≦K≦N-1</var></li> <li><var>P</var> is a permutation of the set {<var>1</var>, <var>2</var>, ..., <var>N</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>P_1</var> <var>P_2</var> <var>...</var> <var>P_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the lexicographically smallest permutation that can be obtained.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 2 4 2 3 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 1 4 3 </pre> <p>One possible way to obtain the lexicographically smallest permutation is shown below:</p> <ul> <li><var>4 2 3 1</var></li> <li><var>4 1 3 2</var></li> <li><var>3 1 4 2</var></li> <li><var>2 1 4 3</var></li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 1 5 4 3 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 2 3 4 5 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>8 3 4 5 7 8 3 1 2 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1 2 6 7 5 3 4 8 </pre></section> </div> </span>
s669918514
p04052
Wrong Answer
NK=input() NK="".join(NK).rstrip("\n").split(" ") N,K,ans=int(NK[0]),int(NK[1]),[] DP=[0 for s in range(N+1)]#各数字があるかどうか[数字],取りだせるのがindex lis=input() lis = "".join(lis).split(" ") lis=[int(s) for s in lis] print(lis) St=0 for s in range(N): DP[lis[s]]=s+1 #if DP[lis[s]]!=0: #DP[lis[s]]+=[s+1]#同じ数字が複数個ある場合の処理 def search(num): #if DP[num] 複数ある場合の処理 comp=DP[num]#先頭が4の場合はここで3を探す if comp<DP[num+1]: return 0 return comp#なかった場合は初期値の0を返す def sort(START): global St compare=START #この場合はlis[0]がSTART? comp=search(compare-1) start=DP[START] if (comp==0): #& (start==1): #DP[lis[0]]=0 #ans.append(lis.pop(0))#先頭がこれ以上小さくなることはないので取り出す #for s in range(len(DP)): #if DP[s]==0: #continue #DP[s]-=1 St+=1 return #print(str(comp)+" "+str(start)) if (comp-start)<K: #print("<K") sort(lis[comp-1]) return if (comp-start)>=K : #print(">=K") temp=DP[lis[start-1]] DP[lis[start-1]]=comp DP[lis[comp-1]]=temp temp=lis[start-1] lis[start-1]=lis[comp-1] lis[comp-1]=temp #elif compが複数だった場合の処理 #elif 存在するが距離がK以下の場合の処理 そこからK以上のものだけを探せばいい。証明済み d=0 while St!=N-1: sort(lis[St]) #print(DP) print(lis) #print(ans) #d+=1 #if d==20: #break #print(ans) for s in range(len(lis)): print(lis[s])
4 2 4 2 3 1
2 1 4 3
<span class="lang-en"> <p>Score : <var>2000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a permutation <var>P_1 ... P_N</var> of the set {<var>1</var>, <var>2</var>, ..., <var>N</var>}.</p> <p>You can apply the following operation to this permutation, any number of times (possibly zero):</p> <ul> <li>Choose two indices <var>i,j (1 ≦ i &lt; j ≦ N)</var>, such that <var>j - i ≧ K</var> and <var>|P_i - P_j| = 1</var>. Then, swap the values of <var>P_i</var> and <var>P_j</var>.</li> </ul> <p>Among all permutations that can be obtained by applying this operation to the given permutation, find the lexicographically smallest one.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦500,000</var></li> <li><var>1≦K≦N-1</var></li> <li><var>P</var> is a permutation of the set {<var>1</var>, <var>2</var>, ..., <var>N</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>P_1</var> <var>P_2</var> <var>...</var> <var>P_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the lexicographically smallest permutation that can be obtained.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 2 4 2 3 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 1 4 3 </pre> <p>One possible way to obtain the lexicographically smallest permutation is shown below:</p> <ul> <li><var>4 2 3 1</var></li> <li><var>4 1 3 2</var></li> <li><var>3 1 4 2</var></li> <li><var>2 1 4 3</var></li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 1 5 4 3 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 2 3 4 5 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>8 3 4 5 7 8 3 1 2 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1 2 6 7 5 3 4 8 </pre></section> </div> </span>
s102943485
p04052
Wrong Answer
NK=input() NK="".join(NK).rstrip("\n").split(" ") N,K,ans=int(NK[0]),int(NK[1]),[] DP=[0 for s in range(N+1)]#各数字があるかどうか[数字],取りだせるのがindex lis=input() lis = "".join(lis).split(" ") lis=[int(s) for s in lis] print(lis) St=0 for s in range(N): DP[lis[s]]=s+1 def search(num): comp=DP[num]#先頭が4の場合はここで3を探す if comp<DP[num+1]: return 0 return comp#なかった場合は初期値の0を返す def sort(START): global St compare=START #この場合はlis[0]がSTART? comp=search(compare-1) start=DP[START] if (comp==0): #& (start==1): St+=1 return if (comp-start)<K: sort(lis[comp-1]) return if (comp-start)>=K : temp=DP[lis[start-1]] DP[lis[start-1]]=comp DP[lis[comp-1]]=temp temp=lis[start-1] lis[start-1]=lis[comp-1] lis[comp-1]=temp while St!=N-1: sort(lis[St]) for s in range(len(lis)): print(lis[s])
4 2 4 2 3 1
2 1 4 3
<span class="lang-en"> <p>Score : <var>2000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a permutation <var>P_1 ... P_N</var> of the set {<var>1</var>, <var>2</var>, ..., <var>N</var>}.</p> <p>You can apply the following operation to this permutation, any number of times (possibly zero):</p> <ul> <li>Choose two indices <var>i,j (1 ≦ i &lt; j ≦ N)</var>, such that <var>j - i ≧ K</var> and <var>|P_i - P_j| = 1</var>. Then, swap the values of <var>P_i</var> and <var>P_j</var>.</li> </ul> <p>Among all permutations that can be obtained by applying this operation to the given permutation, find the lexicographically smallest one.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦500,000</var></li> <li><var>1≦K≦N-1</var></li> <li><var>P</var> is a permutation of the set {<var>1</var>, <var>2</var>, ..., <var>N</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>P_1</var> <var>P_2</var> <var>...</var> <var>P_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the lexicographically smallest permutation that can be obtained.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 2 4 2 3 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 1 4 3 </pre> <p>One possible way to obtain the lexicographically smallest permutation is shown below:</p> <ul> <li><var>4 2 3 1</var></li> <li><var>4 1 3 2</var></li> <li><var>3 1 4 2</var></li> <li><var>2 1 4 3</var></li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 1 5 4 3 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 2 3 4 5 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>8 3 4 5 7 8 3 1 2 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1 2 6 7 5 3 4 8 </pre></section> </div> </span>
s751397118
p04052
Wrong Answer
NK=input() NK="".join(NK).rstrip("\n").split(" ") N,K,ans=int(NK[0]),int(NK[1]),[] DP=[0 for s in range(N+1)]#各数字があるかどうか[数字],取りだせるのがindex lis=input() lis = "".join(lis).split(" ") lis=[int(s) for s in lis] for s in range(N): DP[lis[s]]=s+1 def search(num): comp=DP[num]#先頭が4の場合はここで3を探す if comp<DP[num+1]: return 0 return comp#なかった場合は初期値の0を返す def sort(START): compare=START #この場合はlis[0]がSTART? comp=search(compare-1) start=DP[START] if (comp==0): #& (start==1): DP[lis[0]]=0 ans.append(lis.pop(0))#先頭がこれ以上小さくなることはないので取り出す for s in range(len(DP)): if DP[s]==0: continue DP[s]-=1 return if (comp-start)<K: sort(lis[comp-1]) return if (comp-start)>=K : temp=DP[lis[start-1]] DP[lis[start-1]]=comp DP[lis[comp-1]]=temp temp=lis[start-1] lis[start-1]=lis[comp-1] lis[comp-1]=temp while lis: sort(lis[0]) for s in range(len(ans)): print(ans[s])
4 2 4 2 3 1
2 1 4 3
<span class="lang-en"> <p>Score : <var>2000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a permutation <var>P_1 ... P_N</var> of the set {<var>1</var>, <var>2</var>, ..., <var>N</var>}.</p> <p>You can apply the following operation to this permutation, any number of times (possibly zero):</p> <ul> <li>Choose two indices <var>i,j (1 ≦ i &lt; j ≦ N)</var>, such that <var>j - i ≧ K</var> and <var>|P_i - P_j| = 1</var>. Then, swap the values of <var>P_i</var> and <var>P_j</var>.</li> </ul> <p>Among all permutations that can be obtained by applying this operation to the given permutation, find the lexicographically smallest one.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦500,000</var></li> <li><var>1≦K≦N-1</var></li> <li><var>P</var> is a permutation of the set {<var>1</var>, <var>2</var>, ..., <var>N</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>P_1</var> <var>P_2</var> <var>...</var> <var>P_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the lexicographically smallest permutation that can be obtained.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 2 4 2 3 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 1 4 3 </pre> <p>One possible way to obtain the lexicographically smallest permutation is shown below:</p> <ul> <li><var>4 2 3 1</var></li> <li><var>4 1 3 2</var></li> <li><var>3 1 4 2</var></li> <li><var>2 1 4 3</var></li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 1 5 4 3 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 2 3 4 5 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>8 3 4 5 7 8 3 1 2 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1 2 6 7 5 3 4 8 </pre></section> </div> </span>
s289012101
p04052
Wrong Answer
NK=input() NK="".join(NK).rstrip("\n").split(" ") N,K,ans=int(NK[0]),int(NK[1]),[] DP=[0 for s in range(N+1)]#各数字があるかどうか[数字],取りだせるのがindex lis=input() lis = "".join(lis).split(" ") lis=[int(s) for s in lis] for s in range(N): DP[lis[s]]=s+1 def search(num): comp=DP[num]#先頭が4の場合はここで3を探す if comp<DP[num+1]: return 0 return comp#なかった場合は初期値の0を返す def sort(START): compare=START #この場合はlis[0]がSTART? comp=search(compare-1) start=DP[START] if (comp==0): #& (start==1): DP[lis[0]]=0 ans.append(lis.pop(0))#先頭がこれ以上小さくなることはないので取り出す for s in range(len(DP)): if DP[s]==0: continue DP[s]-=1 return if (comp-start)<K: sort(lis[comp-1]) return if (comp-start)>=K : temp=DP[lis[start-1]] DP[lis[start-1]]=comp DP[lis[comp-1]]=temp temp=lis[start-1] lis[start-1]=lis[comp-1] lis[comp-1]=temp while lis: sort(lis[0]) print(ans)
4 2 4 2 3 1
2 1 4 3
<span class="lang-en"> <p>Score : <var>2000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a permutation <var>P_1 ... P_N</var> of the set {<var>1</var>, <var>2</var>, ..., <var>N</var>}.</p> <p>You can apply the following operation to this permutation, any number of times (possibly zero):</p> <ul> <li>Choose two indices <var>i,j (1 ≦ i &lt; j ≦ N)</var>, such that <var>j - i ≧ K</var> and <var>|P_i - P_j| = 1</var>. Then, swap the values of <var>P_i</var> and <var>P_j</var>.</li> </ul> <p>Among all permutations that can be obtained by applying this operation to the given permutation, find the lexicographically smallest one.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦500,000</var></li> <li><var>1≦K≦N-1</var></li> <li><var>P</var> is a permutation of the set {<var>1</var>, <var>2</var>, ..., <var>N</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>P_1</var> <var>P_2</var> <var>...</var> <var>P_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the lexicographically smallest permutation that can be obtained.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 2 4 2 3 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 1 4 3 </pre> <p>One possible way to obtain the lexicographically smallest permutation is shown below:</p> <ul> <li><var>4 2 3 1</var></li> <li><var>4 1 3 2</var></li> <li><var>3 1 4 2</var></li> <li><var>2 1 4 3</var></li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 1 5 4 3 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 2 3 4 5 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>8 3 4 5 7 8 3 1 2 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1 2 6 7 5 3 4 8 </pre></section> </div> </span>
s792069043
p04052
Time Limit Exceeded
N,K = input().split() N,K = int(N), int(K) P = [[int(x),i] for i,x in enumerate(input().split())] P = sorted(P) # [(1, 3), (2, 1), (3, 2), (4, 0)] flag = False i = -1 while(True): if P[i-1][1] - P[i][1] >= K: temp = P[i-1][1] P[i-1][1] = P[i][1] P[i][1] = temp flag = True elif i == -(len(P)-1): if flag == False: break i = -1 flag = False else: i=i-1 #print(answer) for i in sorted(P, key = lambda p:p[1]): print(i[0])
4 2 4 2 3 1
2 1 4 3
<span class="lang-en"> <p>Score : <var>2000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a permutation <var>P_1 ... P_N</var> of the set {<var>1</var>, <var>2</var>, ..., <var>N</var>}.</p> <p>You can apply the following operation to this permutation, any number of times (possibly zero):</p> <ul> <li>Choose two indices <var>i,j (1 ≦ i &lt; j ≦ N)</var>, such that <var>j - i ≧ K</var> and <var>|P_i - P_j| = 1</var>. Then, swap the values of <var>P_i</var> and <var>P_j</var>.</li> </ul> <p>Among all permutations that can be obtained by applying this operation to the given permutation, find the lexicographically smallest one.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦500,000</var></li> <li><var>1≦K≦N-1</var></li> <li><var>P</var> is a permutation of the set {<var>1</var>, <var>2</var>, ..., <var>N</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>P_1</var> <var>P_2</var> <var>...</var> <var>P_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the lexicographically smallest permutation that can be obtained.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 2 4 2 3 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 1 4 3 </pre> <p>One possible way to obtain the lexicographically smallest permutation is shown below:</p> <ul> <li><var>4 2 3 1</var></li> <li><var>4 1 3 2</var></li> <li><var>3 1 4 2</var></li> <li><var>2 1 4 3</var></li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 1 5 4 3 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 2 3 4 5 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>8 3 4 5 7 8 3 1 2 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1 2 6 7 5 3 4 8 </pre></section> </div> </span>
s248844511
p04052
Time Limit Exceeded
N, K = [int(x) for x in input().split()] nums = {int(x):i for i, x in enumerate(input().split())} swap = True while swap: swap = False for x in range(1, N): if nums[x] - nums[x+1] >= K: nums[x], nums[x+1] = nums[x+1], nums[x] swap = True for k, v in sorted(nums.items(), key=lambda item: item[1]): print(k)
4 2 4 2 3 1
2 1 4 3
<span class="lang-en"> <p>Score : <var>2000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a permutation <var>P_1 ... P_N</var> of the set {<var>1</var>, <var>2</var>, ..., <var>N</var>}.</p> <p>You can apply the following operation to this permutation, any number of times (possibly zero):</p> <ul> <li>Choose two indices <var>i,j (1 ≦ i &lt; j ≦ N)</var>, such that <var>j - i ≧ K</var> and <var>|P_i - P_j| = 1</var>. Then, swap the values of <var>P_i</var> and <var>P_j</var>.</li> </ul> <p>Among all permutations that can be obtained by applying this operation to the given permutation, find the lexicographically smallest one.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦500,000</var></li> <li><var>1≦K≦N-1</var></li> <li><var>P</var> is a permutation of the set {<var>1</var>, <var>2</var>, ..., <var>N</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>P_1</var> <var>P_2</var> <var>...</var> <var>P_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the lexicographically smallest permutation that can be obtained.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 2 4 2 3 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 1 4 3 </pre> <p>One possible way to obtain the lexicographically smallest permutation is shown below:</p> <ul> <li><var>4 2 3 1</var></li> <li><var>4 1 3 2</var></li> <li><var>3 1 4 2</var></li> <li><var>2 1 4 3</var></li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 1 5 4 3 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 2 3 4 5 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>8 3 4 5 7 8 3 1 2 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1 2 6 7 5 3 4 8 </pre></section> </div> </span>
s534545425
p04052
Time Limit Exceeded
N, K = [int(x) for x in input().split()] nums = [int(x) for x in input().split()] def f_swap(nums, N, K): for i in range(0, N-K): for j in range(i+K, N): if nums[i] - nums[j] == 1: nums[i], nums[j] = nums[j], nums[i] return 1 return 0 while True: if not f_swap(nums, N, K): break for n in nums: print(n)
4 2 4 2 3 1
2 1 4 3
<span class="lang-en"> <p>Score : <var>2000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a permutation <var>P_1 ... P_N</var> of the set {<var>1</var>, <var>2</var>, ..., <var>N</var>}.</p> <p>You can apply the following operation to this permutation, any number of times (possibly zero):</p> <ul> <li>Choose two indices <var>i,j (1 ≦ i &lt; j ≦ N)</var>, such that <var>j - i ≧ K</var> and <var>|P_i - P_j| = 1</var>. Then, swap the values of <var>P_i</var> and <var>P_j</var>.</li> </ul> <p>Among all permutations that can be obtained by applying this operation to the given permutation, find the lexicographically smallest one.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦500,000</var></li> <li><var>1≦K≦N-1</var></li> <li><var>P</var> is a permutation of the set {<var>1</var>, <var>2</var>, ..., <var>N</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>P_1</var> <var>P_2</var> <var>...</var> <var>P_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the lexicographically smallest permutation that can be obtained.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 2 4 2 3 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 1 4 3 </pre> <p>One possible way to obtain the lexicographically smallest permutation is shown below:</p> <ul> <li><var>4 2 3 1</var></li> <li><var>4 1 3 2</var></li> <li><var>3 1 4 2</var></li> <li><var>2 1 4 3</var></li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 1 5 4 3 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 2 3 4 5 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>8 3 4 5 7 8 3 1 2 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1 2 6 7 5 3 4 8 </pre></section> </div> </span>
s897196251
p04052
Time Limit Exceeded
import numpy as np def func(): line1 = input('') line2 = input('') line1 = line1.split(' ') line2 = line2.split(' ') N = int(line1[0]) K = int(line1[1]) ar = np.zeros([N],np.int) for i in range(0,N): ar[i] = line2[i] flag = True while flag: flag = False for i in range(0,N): for j in range(i+K,N): if(np.abs(ar[i] - ar[j]) == 1): if(ar[i] > ar[j]): tmp = ar[i] ar[i] = ar[j] ar[j] = tmp flag = True for i in range(0,N): print(ar[i]) func()
4 2 4 2 3 1
2 1 4 3
<span class="lang-en"> <p>Score : <var>2000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a permutation <var>P_1 ... P_N</var> of the set {<var>1</var>, <var>2</var>, ..., <var>N</var>}.</p> <p>You can apply the following operation to this permutation, any number of times (possibly zero):</p> <ul> <li>Choose two indices <var>i,j (1 ≦ i &lt; j ≦ N)</var>, such that <var>j - i ≧ K</var> and <var>|P_i - P_j| = 1</var>. Then, swap the values of <var>P_i</var> and <var>P_j</var>.</li> </ul> <p>Among all permutations that can be obtained by applying this operation to the given permutation, find the lexicographically smallest one.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦500,000</var></li> <li><var>1≦K≦N-1</var></li> <li><var>P</var> is a permutation of the set {<var>1</var>, <var>2</var>, ..., <var>N</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>P_1</var> <var>P_2</var> <var>...</var> <var>P_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the lexicographically smallest permutation that can be obtained.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 2 4 2 3 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 1 4 3 </pre> <p>One possible way to obtain the lexicographically smallest permutation is shown below:</p> <ul> <li><var>4 2 3 1</var></li> <li><var>4 1 3 2</var></li> <li><var>3 1 4 2</var></li> <li><var>2 1 4 3</var></li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 1 5 4 3 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 2 3 4 5 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>8 3 4 5 7 8 3 1 2 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1 2 6 7 5 3 4 8 </pre></section> </div> </span>
s994712690
p04052
Time Limit Exceeded
input_word = input() input_list = input_word.split(" ") N = int(input_list[0]) K = int(input_list[1]) input_word = input() tmp_list = input_word.split(" ") input_list = [ int(i) for i in tmp_list ] while True: flag = 0 for i in range(1,N): number = input_list.index(i) number_1 = input_list.index(i+1) if number - number_1 >= K: input_list[number_1],input_list[number] = input_list[number],input_list[number_1] flag = 1 break if flag == 0: break for i in input_list: print(i)
4 2 4 2 3 1
2 1 4 3
<span class="lang-en"> <p>Score : <var>2000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a permutation <var>P_1 ... P_N</var> of the set {<var>1</var>, <var>2</var>, ..., <var>N</var>}.</p> <p>You can apply the following operation to this permutation, any number of times (possibly zero):</p> <ul> <li>Choose two indices <var>i,j (1 ≦ i &lt; j ≦ N)</var>, such that <var>j - i ≧ K</var> and <var>|P_i - P_j| = 1</var>. Then, swap the values of <var>P_i</var> and <var>P_j</var>.</li> </ul> <p>Among all permutations that can be obtained by applying this operation to the given permutation, find the lexicographically smallest one.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦500,000</var></li> <li><var>1≦K≦N-1</var></li> <li><var>P</var> is a permutation of the set {<var>1</var>, <var>2</var>, ..., <var>N</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>P_1</var> <var>P_2</var> <var>...</var> <var>P_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the lexicographically smallest permutation that can be obtained.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 2 4 2 3 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 1 4 3 </pre> <p>One possible way to obtain the lexicographically smallest permutation is shown below:</p> <ul> <li><var>4 2 3 1</var></li> <li><var>4 1 3 2</var></li> <li><var>3 1 4 2</var></li> <li><var>2 1 4 3</var></li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 1 5 4 3 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 2 3 4 5 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>8 3 4 5 7 8 3 1 2 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1 2 6 7 5 3 4 8 </pre></section> </div> </span>
s410912300
p04052
Time Limit Exceeded
input_word = input() input_list = input_word.split(" ") N = int(input_list[0]) K = int(input_list[1]) input_word = input() tmp_list = input_word.split(" ") input_list = [ int(i) for i in tmp_list ] while True: flag = 0 for i in range(1,N+1): number = input_list.index(i) for j in range(0,number): if number - j >= K: if input_list[j] - i == 1: input_list[j],input_list[number] = input_list[number],input_list[j] flag = 1 break if flag == 1: break if flag == 0: break for i in input_list: print(i)
4 2 4 2 3 1
2 1 4 3
<span class="lang-en"> <p>Score : <var>2000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a permutation <var>P_1 ... P_N</var> of the set {<var>1</var>, <var>2</var>, ..., <var>N</var>}.</p> <p>You can apply the following operation to this permutation, any number of times (possibly zero):</p> <ul> <li>Choose two indices <var>i,j (1 ≦ i &lt; j ≦ N)</var>, such that <var>j - i ≧ K</var> and <var>|P_i - P_j| = 1</var>. Then, swap the values of <var>P_i</var> and <var>P_j</var>.</li> </ul> <p>Among all permutations that can be obtained by applying this operation to the given permutation, find the lexicographically smallest one.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦500,000</var></li> <li><var>1≦K≦N-1</var></li> <li><var>P</var> is a permutation of the set {<var>1</var>, <var>2</var>, ..., <var>N</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>P_1</var> <var>P_2</var> <var>...</var> <var>P_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the lexicographically smallest permutation that can be obtained.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 2 4 2 3 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 1 4 3 </pre> <p>One possible way to obtain the lexicographically smallest permutation is shown below:</p> <ul> <li><var>4 2 3 1</var></li> <li><var>4 1 3 2</var></li> <li><var>3 1 4 2</var></li> <li><var>2 1 4 3</var></li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 1 5 4 3 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 2 3 4 5 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>8 3 4 5 7 8 3 1 2 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1 2 6 7 5 3 4 8 </pre></section> </div> </span>
s619005967
p04052
Time Limit Exceeded
n, k = (int(s) for s in input().strip().split(' ')) p = [int(s) for s in input().strip().split(' ')] index = len(p) while index > k: changed = False for i in range(0, index - k): if p[i] == p[index - 1] + 1: p[i], p[index - 1] = p[index - 1], p[i] changed = True index = len(p) break if not changed: index -= 1 [print(str(a)) for a in p]
4 2 4 2 3 1
2 1 4 3
<span class="lang-en"> <p>Score : <var>2000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a permutation <var>P_1 ... P_N</var> of the set {<var>1</var>, <var>2</var>, ..., <var>N</var>}.</p> <p>You can apply the following operation to this permutation, any number of times (possibly zero):</p> <ul> <li>Choose two indices <var>i,j (1 ≦ i &lt; j ≦ N)</var>, such that <var>j - i ≧ K</var> and <var>|P_i - P_j| = 1</var>. Then, swap the values of <var>P_i</var> and <var>P_j</var>.</li> </ul> <p>Among all permutations that can be obtained by applying this operation to the given permutation, find the lexicographically smallest one.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦500,000</var></li> <li><var>1≦K≦N-1</var></li> <li><var>P</var> is a permutation of the set {<var>1</var>, <var>2</var>, ..., <var>N</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>P_1</var> <var>P_2</var> <var>...</var> <var>P_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the lexicographically smallest permutation that can be obtained.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 2 4 2 3 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 1 4 3 </pre> <p>One possible way to obtain the lexicographically smallest permutation is shown below:</p> <ul> <li><var>4 2 3 1</var></li> <li><var>4 1 3 2</var></li> <li><var>3 1 4 2</var></li> <li><var>2 1 4 3</var></li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 1 5 4 3 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 2 3 4 5 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>8 3 4 5 7 8 3 1 2 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1 2 6 7 5 3 4 8 </pre></section> </div> </span>
s120612309
p04052
Time Limit Exceeded
n, k = (int(s) for s in input().strip().split(' ')) p = [int(s) for s in input().strip().split(' ')] index = len(p) while index > 0: changed = False for i in range(0, index - k): if p[i] == p[index - 1] + 1: p[i], p[index - 1] = p[index - 1], p[i] changed = True index = len(p) break if not changed: index -= 1 [print(str(a)) for a in p]
4 2 4 2 3 1
2 1 4 3
<span class="lang-en"> <p>Score : <var>2000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a permutation <var>P_1 ... P_N</var> of the set {<var>1</var>, <var>2</var>, ..., <var>N</var>}.</p> <p>You can apply the following operation to this permutation, any number of times (possibly zero):</p> <ul> <li>Choose two indices <var>i,j (1 ≦ i &lt; j ≦ N)</var>, such that <var>j - i ≧ K</var> and <var>|P_i - P_j| = 1</var>. Then, swap the values of <var>P_i</var> and <var>P_j</var>.</li> </ul> <p>Among all permutations that can be obtained by applying this operation to the given permutation, find the lexicographically smallest one.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦500,000</var></li> <li><var>1≦K≦N-1</var></li> <li><var>P</var> is a permutation of the set {<var>1</var>, <var>2</var>, ..., <var>N</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>P_1</var> <var>P_2</var> <var>...</var> <var>P_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the lexicographically smallest permutation that can be obtained.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 2 4 2 3 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 1 4 3 </pre> <p>One possible way to obtain the lexicographically smallest permutation is shown below:</p> <ul> <li><var>4 2 3 1</var></li> <li><var>4 1 3 2</var></li> <li><var>3 1 4 2</var></li> <li><var>2 1 4 3</var></li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 1 5 4 3 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 2 3 4 5 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>8 3 4 5 7 8 3 1 2 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1 2 6 7 5 3 4 8 </pre></section> </div> </span>
s332524056
p04052
Accepted
def invert(p, q): for i, pi in enumerate(p): q[pi] = i def sort_insertion(k, data, first, last): length = last - first if length <= 2: if length == 2 and data[first] - data[first + 1] >= k: data[first], data[first + 1] = data[first + 1], data[first] return for i in range(first + 1, last): v = data[i] for t in range(i - 1, first - 1, -1): if data[t] - v < k: t += 1 break data[t + 1:i + 1] = data[t:i] data[t] = v def sort_merge(k, data, first, last): if last - first < 10: sort_insertion(k, data, first, last) return middle = (first + last) // 2 sort_merge(k, data, first, middle) sort_merge(k, data, middle, last) bounds = data[first:middle] for i in range(len(bounds) - 2, -1, -1): bounds[i] = min(bounds[i + 1], bounds[i]) tmp = data[first:middle] first_len = middle - first head1 = 0 head2 = middle for ohead in range(first, last): if head1 == first_len or head2 == last: data[ohead:ohead + first_len - head1] = tmp[head1:first_len] return elif bounds[head1] - data[head2] >= k: data[ohead] = data[head2] head2 += 1 else: data[ohead] = tmp[head1] head1 += 1 n, k = (int(s) for s in input().split(' ')) p = [int(s) - 1 for s in input().split(' ')] q = list(p) invert(p, q) sort_merge(k, q, 0, n) invert(q, p) for pi in p: print(pi + 1)
4 2 4 2 3 1
2 1 4 3
<span class="lang-en"> <p>Score : <var>2000</var> points</p> <div class="part"> <section> <h3>Problem Statement</h3><p>You are given a permutation <var>P_1 ... P_N</var> of the set {<var>1</var>, <var>2</var>, ..., <var>N</var>}.</p> <p>You can apply the following operation to this permutation, any number of times (possibly zero):</p> <ul> <li>Choose two indices <var>i,j (1 ≦ i &lt; j ≦ N)</var>, such that <var>j - i ≧ K</var> and <var>|P_i - P_j| = 1</var>. Then, swap the values of <var>P_i</var> and <var>P_j</var>.</li> </ul> <p>Among all permutations that can be obtained by applying this operation to the given permutation, find the lexicographically smallest one.</p> </section> </div> <div class="part"> <section> <h3>Constraints</h3><ul> <li><var>2≦N≦500,000</var></li> <li><var>1≦K≦N-1</var></li> <li><var>P</var> is a permutation of the set {<var>1</var>, <var>2</var>, ..., <var>N</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>P_1</var> <var>P_2</var> <var>...</var> <var>P_N</var> </pre> </section> </div> <div class="part"> <section> <h3>Output</h3><p>Print the lexicographically smallest permutation that can be obtained.</p> </section> </div> </div> <hr/> <div class="part"> <section> <h3>Sample Input 1</h3><pre>4 2 4 2 3 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 1</h3><pre>2 1 4 3 </pre> <p>One possible way to obtain the lexicographically smallest permutation is shown below:</p> <ul> <li><var>4 2 3 1</var></li> <li><var>4 1 3 2</var></li> <li><var>3 1 4 2</var></li> <li><var>2 1 4 3</var></li> </ul> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 2</h3><pre>5 1 5 4 3 2 1 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 2</h3><pre>1 2 3 4 5 </pre> </section> </div> <hr/> <div class="part"> <section> <h3>Sample Input 3</h3><pre>8 3 4 5 7 8 3 1 2 6 </pre> </section> </div> <div class="part"> <section> <h3>Sample Output 3</h3><pre>1 2 6 7 5 3 4 8 </pre></section> </div> </span>