結果

問題 No.528 10^9と10^9+7と回文
ユーザー mkawa2mkawa2
提出日時 2021-11-12 10:57:59
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,251 bytes
コンパイル時間 442 ms
コンパイル使用メモリ 87,008 KB
実行使用メモリ 96,980 KB
最終ジャッジ日時 2023-08-16 08:02:48
合計ジャッジ時間 5,182 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,320 KB
testcase_01 AC 69 ms
71,028 KB
testcase_02 AC 72 ms
71,184 KB
testcase_03 AC 69 ms
71,084 KB
testcase_04 AC 67 ms
71,088 KB
testcase_05 AC 69 ms
70,868 KB
testcase_06 AC 69 ms
70,968 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 71 ms
71,084 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 70 ms
71,192 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 122 ms
94,916 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)

m = md
for m in [md1, md]:
    n2 = (n+1)//2
    dp = [[0]*2 for _ in range(n2+1)]
    dp[0][0] = 1

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

    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)
0