結果

問題 No.528 10^9と10^9+7と回文
ユーザー rpy3cpprpy3cpp
提出日時 2017-06-09 23:40:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 51 ms / 1,000 ms
コード長 823 bytes
コンパイル時間 229 ms
コンパイル使用メモリ 81,768 KB
実行使用メモリ 66,024 KB
最終ジャッジ日時 2024-07-23 18:29:41
合計ジャッジ時間 2,348 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

Nstr = input().rstrip()

Nlst = [int(c) for c in Nstr]

def solve(Nlst):
    print(solve_core(Nlst, 10**9))
    print(solve_core(Nlst, 10**9 + 7))

def solve_core(Nlst, mod):
    n = len(Nlst)
    res = count_easy(n - 1, mod)
    head = Nlst[:(n + 1)//2]
    tail = Nlst[-n//2:]
    res += count_head(head, mod)
    head.reverse()
    for h, t, in zip(head, tail):
        if h < t:
            break
        if h > t:
            res -= 1
            break
    return res % mod


def count_easy(n, mod):
    m = (n + 1)//2
    ans = (2 * (pow(10, m, mod) - 1)) % mod
    if n & 1:
        ans -= 9 * pow(10, m - 1, mod)
        ans %= mod
    return ans

def count_head(head, mod):
    ans = 0
    head[0] -= 1
    for h in head:
        ans = (ans * 10 + h) % mod
    head[0] += 1
    return (ans + 1) % mod

solve(Nlst)
0