結果

問題 No.528 10^9と10^9+7と回文
ユーザー convexineqconvexineq
提出日時 2021-02-24 02:18:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 108 ms / 1,000 ms
コード長 1,086 bytes
コンパイル時間 251 ms
コンパイル使用メモリ 82,396 KB
実行使用メモリ 86,640 KB
最終ジャッジ日時 2024-09-22 21:28:54
合計ジャッジ時間 3,041 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,608 KB
testcase_01 AC 38 ms
52,128 KB
testcase_02 AC 37 ms
52,352 KB
testcase_03 AC 38 ms
52,352 KB
testcase_04 AC 39 ms
52,224 KB
testcase_05 AC 38 ms
52,352 KB
testcase_06 AC 38 ms
51,968 KB
testcase_07 AC 38 ms
52,352 KB
testcase_08 AC 38 ms
52,496 KB
testcase_09 AC 39 ms
52,096 KB
testcase_10 AC 107 ms
86,316 KB
testcase_11 AC 101 ms
86,512 KB
testcase_12 AC 103 ms
86,520 KB
testcase_13 AC 108 ms
86,188 KB
testcase_14 AC 88 ms
81,408 KB
testcase_15 AC 90 ms
81,536 KB
testcase_16 AC 82 ms
81,152 KB
testcase_17 AC 80 ms
81,008 KB
testcase_18 AC 101 ms
86,328 KB
testcase_19 AC 75 ms
78,848 KB
testcase_20 AC 91 ms
83,216 KB
testcase_21 AC 81 ms
81,024 KB
testcase_22 AC 38 ms
52,224 KB
testcase_23 AC 39 ms
52,608 KB
testcase_24 AC 52 ms
63,232 KB
testcase_25 AC 63 ms
70,528 KB
testcase_26 AC 99 ms
86,640 KB
testcase_27 AC 81 ms
84,992 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 can_leading_zero==0 or 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