結果

問題 No.528 10^9と10^9+7と回文
ユーザー convexineqconvexineq
提出日時 2021-02-24 02:18:22
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 108 ms / 1,000 ms
コード長 1,086 bytes
コンパイル時間 509 ms
コンパイル使用メモリ 81,500 KB
実行使用メモリ 85,984 KB
最終ジャッジ日時 2023-10-24 04:31:28
合計ジャッジ時間 3,294 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,528 KB
testcase_01 AC 38 ms
53,528 KB
testcase_02 AC 38 ms
53,528 KB
testcase_03 AC 40 ms
53,528 KB
testcase_04 AC 38 ms
53,528 KB
testcase_05 AC 38 ms
53,528 KB
testcase_06 AC 38 ms
53,528 KB
testcase_07 AC 39 ms
53,528 KB
testcase_08 AC 38 ms
53,528 KB
testcase_09 AC 38 ms
53,528 KB
testcase_10 AC 108 ms
85,752 KB
testcase_11 AC 101 ms
85,872 KB
testcase_12 AC 103 ms
85,984 KB
testcase_13 AC 108 ms
85,744 KB
testcase_14 AC 86 ms
80,660 KB
testcase_15 AC 87 ms
80,952 KB
testcase_16 AC 82 ms
80,828 KB
testcase_17 AC 80 ms
80,436 KB
testcase_18 AC 100 ms
85,704 KB
testcase_19 AC 76 ms
78,308 KB
testcase_20 AC 91 ms
82,716 KB
testcase_21 AC 81 ms
80,472 KB
testcase_22 AC 38 ms
53,528 KB
testcase_23 AC 39 ms
53,528 KB
testcase_24 AC 52 ms
64,416 KB
testcase_25 AC 62 ms
70,620 KB
testcase_26 AC 100 ms
85,868 KB
testcase_27 AC 75 ms
85,776 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