結果
問題 | No.1171 Runs in Subsequences |
ユーザー | opt |
提出日時 | 2020-07-15 15:10:08 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,271 bytes |
コンパイル時間 | 9,910 ms |
コンパイル使用メモリ | 258,060 KB |
最終ジャッジ日時 | 2025-01-11 21:09:35 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 16 TLE * 2 |
ソースコード
#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; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return 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(); Vm dp(M+1); dp[M] = 1; mint ans = mint(2).pow(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] * mint(2).pow(n-1-i); } swap(dp, _dp); } cout << ans << "\n"; return 0; }