結果
| 問題 |
No.1171 Runs in Subsequences
|
| ユーザー |
kyort0n
|
| 提出日時 | 2020-08-19 00:15:39 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 81 ms / 2,000 ms |
| コード長 | 1,187 bytes |
| コンパイル時間 | 1,731 ms |
| コンパイル使用メモリ | 168,884 KB |
| 実行使用メモリ | 45,824 KB |
| 最終ジャッジ日時 | 2024-10-12 03:25:02 |
| 合計ジャッジ時間 | 3,245 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 18 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
if(a < b) {
a = b;
return true;
}
return false;
}
template<class T>
inline bool chmin(T &a, T b) {
if(a > b) {
a = b;
return true;
}
return false;
}
const long long INF = 1e18;
const ll mod = 1000000007;
ll dp[201000][26];
ll beki[201000];
ll ans;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
string S;
beki[0] = 1;
for(int i = 1; i <= 2e5; i++) {
beki[i] = beki[i-1] * 2 % mod;
}
cin >> S;
ll N = S.size();
for(int i = 0; i < S.size(); i++) {
int to = (int)(S[i] - 'a');
for(int j = 0; j < 26; j++) {
dp[i+1][j] += dp[i][j];
dp[i+1][j] %= mod;
dp[i+1][to] += dp[i][j];
dp[i+1][to] %= mod;
if(to != j) {
ans += dp[i][j] * beki[N - 1 - i];
ans %= mod;
}
}
dp[i+1][to] += 1;
ans += beki[N-1-i];
ans %= mod;
}
cout << ans << endl;
return 0;
}
kyort0n