結果
問題 | No.2905 Nabeatsu Integration |
ユーザー |
👑 ![]() |
提出日時 | 2024-06-24 21:46:46 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 74 ms / 2,000 ms |
コード長 | 1,495 bytes |
コンパイル時間 | 922 ms |
コンパイル使用メモリ | 79,916 KB |
最終ジャッジ日時 | 2025-02-22 00:20:43 |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 70 |
ソースコード
#include <iostream>#include <string>#include <vector>#include <algorithm>#include <utility>#include <atcoder/modint>using i64 = long long;using u64 = unsigned long long;#define rep(i,n) for(int i=0; i<int(n); i++)#define repr(i,n) for(int i=int(n)-1; i>=0; i--)using Modint = atcoder::static_modint<998244353>;using namespace std;int main(){ios::sync_with_stdio(false); cin.tie(nullptr);string S; cin >> S;int n = S.size();vector<int> link(n+1, -1);vector<int> fast(n+1, -1);for(int i=0; i<n; i++){int h = link[i];while(h != -1){if(h == -1 || S[h] == S[i]){ break; }if(link[h] == -1 || S[link[h]] == S[i]){ h = link[h]; break; }h = fast[h];}link[i+1] = h+1;int p = link[h+1];if(p != -1 && S[p] == S[h+1]) p = fast[h+1];fast[i+1] = p;}vector<Modint> dp(n+1);dp[0] = 0;for(int i=0; i<n; i++){Modint x = dp[i] * 10;x += 10;vector<int> vis(10, -1);vis[S[i] - '0'] = i;int h = i;while(h != -1){if(h != -1 && vis[S[h] - '0'] == -1){ vis[S[h] - '0'] = h; }if(link[h] != -1 && vis[S[link[h]] - '0'] == -1){ vis[S[link[h]] - '0'] = link[h]; }h = fast[h];}for(int d=0; d<10; d++) if(vis[d] != i) x -= dp[vis[d]+1];dp[i+1] = x;}Modint ans = dp[n];ans -= n-1;cout << ans.val() << endl;return 0;}