結果

問題 No.148 試験監督(3)
ユーザー 👑 kmjpkmjp
提出日時 2015-02-09 00:27:34
言語 PyPy2
(7.3.15)
結果
TLE  
実行時間 -
コード長 713 bytes
コンパイル時間 913 ms
コンパイル使用メモリ 77,460 KB
実行使用メモリ 86,016 KB
最終ジャッジ日時 2023-09-05 13:34:34
合計ジャッジ時間 5,386 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math



def comb(x,y):
	if y>x-y:
		y=x-y
	
	n1=0
	x2=x;
	while x2:
		n1 += x2/mo
		x2 /= mo
	y2=y
	n2=0
	while y2:
		n2 += y2/mo
		y2 /= mo
	if n1 > n2:
		return 0
	
	# 10^6毎に値を埋め込みそうな気がするが
	# 良い埋め込み方が思いつかない
	ret = 1
	x%=mo
	x+=mo
	for i in range(y):
		ret = ret * (x-i) % mo
	return ret

def hcomb(x,y):
	if x == 0:
		return 1
	return comb(x+y-1,y)


T=input()
mo=1000000007

for i in range(T):
	C,P=map(int,raw_input().strip().split(" "))
	if P*2-1>C:
		print 0
		continue
	elif P==1:
		print C%mo
		continue
	else:
		ret = 0
		ret += hcomb(C-(P+P-1),P-1)
		ret += hcomb(C-(P+P),P)*2
		ret += hcomb(C-(P+P+1),P+1)
		print ret % mo

0