結果

問題 No.1171 Runs in Subsequences
ユーザー milanis48663220milanis48663220
提出日時 2020-08-14 22:21:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 1,317 bytes
コンパイル時間 916 ms
コンパイル使用メモリ 85,472 KB
実行使用メモリ 85,064 KB
最終ジャッジ日時 2024-04-18 22:12:19
合計ジャッジ時間 1,990 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 58 ms
82,176 KB
testcase_16 AC 58 ms
80,964 KB
testcase_17 AC 62 ms
84,916 KB
testcase_18 AC 61 ms
85,060 KB
testcase_19 AC 58 ms
85,056 KB
testcase_20 AC 59 ms
84,928 KB
testcase_21 AC 72 ms
85,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0