結果
問題 | No.528 10^9と10^9+7と回文 |
ユーザー |
|
提出日時 | 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 |
ソースコード
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:breakif h > t:res -= 1breakreturn res % moddef count_easy(n, mod):m = (n + 1)//2ans = (2 * (pow(10, m, mod) - 1)) % modif n & 1:ans -= 9 * pow(10, m - 1, mod)ans %= modreturn ansdef count_head(head, mod):ans = 0head[0] -= 1for h in head:ans = (ans * 10 + h) % modhead[0] += 1return (ans + 1) % modsolve(Nlst)