結果

問題 No.491 10^9+1と回文
ユーザー CodeCreater123
提出日時 2025-05-18 15:41:12
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,093 bytes
コンパイル時間 2,246 ms
コンパイル使用メモリ 197,052 KB
実行使用メモリ 8,376 KB
最終ジャッジ日時 2025-05-18 15:41:18
合計ジャッジ時間 5,703 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 92 WA * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 200010;
const int mod = 998244353;
vector<int> f[N];
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);
    int n;
    cin >> n;
    n /= 1000000001;
    cout << solve(to_string(n), mod) << '\n';
    return 0;
}
0