結果

問題 No.528 10^9と10^9+7と回文
ユーザー rpy3cpprpy3cpp
提出日時 2017-06-09 23:40:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 85 ms / 1,000 ms
コード長 823 bytes
コンパイル時間 286 ms
コンパイル使用メモリ 87,300 KB
実行使用メモリ 78,600 KB
最終ジャッジ日時 2023-10-01 00:54:40
合計ジャッジ時間 3,777 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,476 KB
testcase_01 AC 71 ms
71,296 KB
testcase_02 AC 71 ms
71,376 KB
testcase_03 AC 75 ms
71,432 KB
testcase_04 AC 76 ms
71,192 KB
testcase_05 AC 76 ms
71,428 KB
testcase_06 AC 75 ms
71,228 KB
testcase_07 AC 72 ms
71,248 KB
testcase_08 AC 73 ms
71,252 KB
testcase_09 AC 72 ms
70,972 KB
testcase_10 AC 85 ms
78,600 KB
testcase_11 AC 84 ms
78,348 KB
testcase_12 AC 82 ms
78,284 KB
testcase_13 AC 82 ms
78,284 KB
testcase_14 AC 79 ms
77,484 KB
testcase_15 AC 82 ms
77,312 KB
testcase_16 AC 80 ms
77,020 KB
testcase_17 AC 82 ms
76,988 KB
testcase_18 AC 80 ms
78,472 KB
testcase_19 AC 76 ms
76,216 KB
testcase_20 AC 81 ms
77,660 KB
testcase_21 AC 83 ms
76,900 KB
testcase_22 AC 77 ms
71,128 KB
testcase_23 AC 72 ms
71,496 KB
testcase_24 AC 72 ms
71,264 KB
testcase_25 AC 74 ms
76,032 KB
testcase_26 AC 80 ms
78,344 KB
testcase_27 AC 82 ms
78,528 KB
権限があれば一括ダウンロードができます

ソースコード

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