結果
| 問題 |
No.148 試験監督(3)
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 16:04:58 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,339 bytes |
| コンパイル時間 | 177 ms |
| コンパイル使用メモリ | 82,660 KB |
| 実行使用メモリ | 76,288 KB |
| 最終ジャッジ日時 | 2025-06-12 16:05:03 |
| 合計ジャッジ時間 | 4,860 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | TLE * 1 -- * 11 |
ソースコード
MOD = 10**9 + 7
def add_one(s):
s_list = list(s)
i = len(s_list) - 1
carry = 1
while i >= 0 and carry:
digit = int(s_list[i]) + carry
if digit == 10:
s_list[i] = '0'
carry = 1
else:
s_list[i] = str(digit)
carry = 0
i -= 1
if carry:
s_list = ['1'] + s_list
return ''.join(s_list)
def str_compare(a, b):
if len(a) < len(b):
return True
elif len(a) > len(b):
return False
else:
return a <= b
def mod_str(s, mod):
res = 0
for c in s:
res = (res * 10 + int(c)) % mod
return res
T = int(input())
for _ in range(T):
C_str, P_str = input().split()
# Check if P >= MOD
if len(P_str) > 10 or (len(P_str) == 10 and P_str > "1000000007"):
print(0)
continue
p_val = int(P_str)
if p_val >= MOD:
print(0)
continue
# Check if 2*p_val <= C + 1
C_plus_1_str = add_one(C_str)
two_p = 2 * p_val
two_p_str = str(two_p)
if not str_compare(two_p_str, C_plus_1_str):
print(0)
continue
# Compute product
c_mod = mod_str(C_str, MOD)
product = 1
for k in range(p_val):
term = (c_mod - (p_val - 1 + k)) % MOD
product = (product * term) % MOD
print(product)
gew1fw