結果
問題 |
No.1171 Runs in Subsequences
|
ユーザー |
![]() |
提出日時 | 2020-07-15 15:11:36 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 69 ms / 2,000 ms |
コード長 | 1,228 bytes |
コンパイル時間 | 4,167 ms |
コンパイル使用メモリ | 195,480 KB |
最終ジャッジ日時 | 2025-01-11 21:09:55 |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 18 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for(int i=0; i<int(n); ++i) const int MOD = int(1e9)+7; struct mint { ll x; mint(ll x=0) : x((x%MOD+MOD)%MOD) {} mint operator-() const { return mint(-x);} mint& operator+=(const mint a) { if ((x += a.x) >= MOD) x -= MOD; return *this; } mint& operator-=(const mint a) { if ((x -= a.x) < 0) x += MOD; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this; } mint operator+(const mint a) const { return mint(*this) += a; } mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; } }; ostream& operator<<(ostream& os, const mint& a) { return os << a.x; } using Vm = vector<mint>; int main() { const int M = 26; string s; cin >> s; int n = s.size(); assert(1 <= n && n <= int(2e5)); Vm pw(n+1); pw[0] = 1; rep(i, n) pw[i+1] = pw[i] + pw[i]; Vm dp(M+1); dp[M] = 1; mint ans = pw[n] - 1; rep(i, n) { Vm _dp = dp; int x = s[i] - 'a'; rep(j, M+1) { _dp[x] += dp[j]; if (x != j && j < M) ans += dp[j] * pw[n-1-i]; } swap(dp, _dp); } cout << ans << "\n"; return 0; }