結果
| 問題 |
No.1171 Runs in Subsequences
|
| コンテスト | |
| ユーザー |
milanis48663220
|
| 提出日時 | 2020-08-14 22:21:01 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 53 ms / 2,000 ms |
| コード長 | 1,317 bytes |
| コンパイル時間 | 887 ms |
| コンパイル使用メモリ | 85,576 KB |
| 実行使用メモリ | 84,928 KB |
| 最終ジャッジ日時 | 2024-10-10 15:42:34 |
| 合計ジャッジ時間 | 2,264 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 18 |
ソースコード
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
string S;
P dp[200005][26];
P merge(P p1, P p2){
ll x = (p1.first+p2.first)%MOD;
ll y = (p1.second+p2.second)%MOD;
return P(x, y);
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(10) << fixed;
cin >> S;
int N = S.size();
dp[0][S[0]-'a'] = P(1, 1);
for(int i = 1; i < N; i++){
for(int j = 0; j < 26; j++){
dp[i][j] = dp[i-1][j];
if(S[i] != 'a'+j){
// dp[i][j] = merge(dp[i][j], dp[i-1][j]);
}else{
for(int k = 0; k < 26; k++){
if(j == k){
dp[i][j] = merge(dp[i][j], dp[i-1][k]);
}else{
P p = P(dp[i-1][k].first, dp[i-1][k].first+dp[i-1][k].second);
dp[i][j] = merge(dp[i][j], p);
}
}
dp[i][j] = merge(dp[i][j], P(1, 1));
}
}
}
ll ans = 0;
for(int i = 0; i < 26; i++){
ans += dp[N-1][i].second;
ans %= MOD;
}
cout << ans << endl;
}
milanis48663220