結果

問題 No.528 10^9と10^9+7と回文
ユーザー CodeCreater123
提出日時 2025-05-18 16:11:37
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 93 ms / 1,000 ms
コード長 1,085 bytes
コンパイル時間 2,141 ms
コンパイル使用メモリ 194,796 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-05-18 16:11:42
合計ジャッジ時間 4,538 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 100010;
const int mod = 998244353;
int power(int a, int b, int c) {
    int ans = 1;
    while (b) {
        if (b & 1) ans = ans * a % c;
        a = a * a % c, b >>= 1;
    } return ans;
}
int solve(string s, int mod) {
    int f[2] = {1, 0}, n = s.size();
    for (int i = 0; i < (n + 1) / 2; ++i) {
        int g[2] = {0, 0};
        for (int j = 0; j < 2; ++j) {
            int l = i ? 0 : 1, r = j ? 9 : (s[i] & 15);
            for (int k = l; k <= r; ++k) g[j || (k < r)] = (g[j || (k < r)] + f[j]) % mod;
        }
        f[0] = g[0], f[1] = g[1];
    }
    int ss = f[1];
    for (int i = 1; i < n; ++i) ss = (ss + power(10, (i - 1) / 2, mod) * 9 % mod) % mod;
    string nw; for (int i = 0; i < (n + 1) / 2; ++i) nw += s[i];
    for (int i = (n + 1) / 2; i < n; ++i) nw += s[n - i - 1]; ss += (nw <= s); return ss;
}
signed main() {
    cin.tie(0)->sync_with_stdio(false);
    string s;
    cin >> s;
    cout << solve(s, 1000000000) << '\n' << solve(s, 1000000007) << '\n';
    return 0;
}
0