結果

問題 No.528 10^9と10^9+7と回文
ユーザー convexineqconvexineq
提出日時 2021-02-24 02:08:43
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,077 bytes
コンパイル時間 423 ms
コンパイル使用メモリ 81,540 KB
実行使用メモリ 85,968 KB
最終ジャッジ日時 2023-10-24 04:22:17
合計ジャッジ時間 3,906 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,452 KB
testcase_01 AC 39 ms
53,452 KB
testcase_02 AC 39 ms
53,452 KB
testcase_03 AC 39 ms
53,452 KB
testcase_04 AC 39 ms
53,452 KB
testcase_05 AC 40 ms
53,452 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
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 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 78 ms
85,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def kaibun_number(s,MOD):
    ls = len(s)
    p10 = [1]*(ls+1) # p10[i] = 10**i
    for i in range(1,ls+1):
        p10[i] = p10[i-1]*10%MOD
    all9 = [9*p10[i//2]%MOD for i in range(ls+1)]
    for i in range(1,ls+1):
        all9[i] += all9[i-1]
        all9[i] %= MOD
    
    def minus(lst,L,R):
        lst[R] -= 1
        while L <= R and lst[R] < 0:
            lst[R] = 9
            R -= 1
            lst[R] -= 1
        return L < R
    
    lst = list(map(int,s))
    can_leading_zero = 1
    L,R = 0,len(s)-1
    ans = 0
    while 1:
        if L > R:
            ans += 1
            break
        if L == R:
            ans += 1 + lst[L] - can_leading_zero
            break

        for i in range(lst[L]):
            if i:
                ans += p10[(R-L)//2]
            else:
                ans += all9[R-L-1]
            ans %= MOD
        if lst[L] > lst[R]:
            if not minus(lst,L,R-1): break
        can_leading_zero = 0
        L += 1
        R -= 1
    return ans%MOD

s = input()
print(kaibun_number(s,10**9))
print(kaibun_number(s,10**9+7))
0