結果

問題 No.528 10^9と10^9+7と回文
ユーザー mkawa2mkawa2
提出日時 2021-11-12 11:38:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 136 ms / 1,000 ms
コード長 1,393 bytes
コンパイル時間 495 ms
コンパイル使用メモリ 87,352 KB
実行使用メモリ 94,252 KB
最終ジャッジ日時 2023-08-16 08:52:58
合計ジャッジ時間 4,909 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
70,956 KB
testcase_01 AC 81 ms
71,144 KB
testcase_02 AC 76 ms
71,292 KB
testcase_03 AC 81 ms
71,172 KB
testcase_04 AC 79 ms
71,168 KB
testcase_05 AC 80 ms
71,164 KB
testcase_06 AC 79 ms
70,956 KB
testcase_07 AC 78 ms
71,084 KB
testcase_08 AC 78 ms
71,064 KB
testcase_09 AC 78 ms
70,896 KB
testcase_10 AC 132 ms
93,924 KB
testcase_11 AC 134 ms
93,944 KB
testcase_12 AC 131 ms
94,104 KB
testcase_13 AC 132 ms
94,108 KB
testcase_14 AC 121 ms
91,460 KB
testcase_15 AC 122 ms
90,136 KB
testcase_16 AC 119 ms
89,388 KB
testcase_17 AC 118 ms
86,252 KB
testcase_18 AC 132 ms
94,184 KB
testcase_19 AC 103 ms
79,120 KB
testcase_20 AC 124 ms
93,236 KB
testcase_21 AC 117 ms
86,380 KB
testcase_22 AC 79 ms
71,068 KB
testcase_23 AC 77 ms
71,284 KB
testcase_24 AC 92 ms
75,956 KB
testcase_25 AC 103 ms
76,524 KB
testcase_26 AC 135 ms
94,252 KB
testcase_27 AC 136 ms
94,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
# inf = 18446744073709551615
inf = 4294967295
md = 10**9+7
# md = 998244353
md1 = 10**9

s = list(map(int, SI()))
n = len(s)

ok = True
for i in range(n//2)[::-1]:
    if s[i] < s[n-1-i]: break
    if s[i] > s[n-1-i]:
        ok = False
        break

for m in [md1, md]:
    ans = 0
    cc = [0]
    for k in range(1, n):
        if k == 1: c = 9
        elif k & 1: c = cc[k-1]*10%m
        else: c = cc[k-1]
        cc.append(c)
    for c in cc: ans = (ans+c)%m
    # print(ans, cc)

    if s[0]:
        n2 = (n+1)//2
        dp = [[0]*2 for _ in range(n2+1)]
        dp[0][0] = 1

        for i, a in enumerate(s[:n2]):
            dp[i+1][0] = dp[i][0]
            if i: dp[i+1][1] = (dp[i][1]*10+dp[i][0]*a)%m
            else: dp[i+1][1] = a-1
        ans += dp[-1][1]
        if ok: ans += 1

    print(ans%m)
0