結果
| 問題 | No.8133 Reversed |
| コンテスト | |
| ユーザー |
tko919
|
| 提出日時 | 2026-04-01 21:54:23 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,805 bytes |
| 記録 | |
| コンパイル時間 | 198 ms |
| コンパイル使用メモリ | 85,088 KB |
| 実行使用メモリ | 97,244 KB |
| 最終ジャッジ日時 | 2026-04-01 21:54:45 |
| 合計ジャッジ時間 | 6,562 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | TLE * 2 -- * 4 |
ソースコード
import sys
input = sys.stdin.readline
MOD = 7000000001
class Fp:
def __init__(self, x=0):
self.x = x % MOD
def __add__(self, other):
return Fp(self.x + other.x)
def __sub__(self, other):
return Fp(self.x - other.x)
def __mul__(self, other):
return Fp(self.x * other.x)
def __iadd__(self, other):
self.x = (self.x + other.x) % MOD
return self
def __isub__(self, other):
self.x = (self.x - other.x) % MOD
return self
def __imul__(self, other):
self.x = (self.x * other.x) % MOD
return self
def pow(self, e):
return Fp(pow(self.x, e, MOD))
def __repr__(self):
return str(self.x)
def subtask(x): # <= x
if x <= 0:
return Fp(0)
L = len(str(x))
ret = Fp(0)
# 桁数が短いもの
for length in range(1, L):
ret += Fp(45) * Fp(100).pow(length - 1)
dp = [Fp(0), Fp(0)]
sub = [Fp(0), Fp(0)]
sub[1] = Fp(1)
for keta in range(L):
cur = (x // (10 ** keta)) % 10
ndp = [Fp(0), Fp(0)]
nsub = [Fp(0), Fp(0)]
for dig in range(10):
if keta == L - 1 and dig == 0:
continue
for le in range(2):
nle = le
if cur > dig:
nle = 1
elif cur < dig:
nle = 0
nsub[nle] += sub[le]
ndp[nle] += dp[le] + Fp(10).pow(L - 1 - keta) * Fp(dig) * sub[le]
dp, ndp = ndp, dp
sub, nsub = nsub, sub
ret += dp[1]
return ret
def main():
n = int(input())
for _ in range(n):
L, R = map(int, input().split())
ans = subtask(R) - subtask(L - 1)
print(ans.x)
if __name__ == "__main__":
main()
tko919