結果

問題 No.1171 Runs in Subsequences
ユーザー ぷらぷら
提出日時 2021-03-14 23:12:00
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 124 ms / 2,000 ms
コード長 1,117 bytes
コンパイル時間 1,411 ms
コンパイル使用メモリ 165,936 KB
実行使用メモリ 50,652 KB
最終ジャッジ日時 2023-08-06 08:30:02
合計ジャッジ時間 3,926 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 119 ms
48,696 KB
testcase_16 AC 117 ms
48,088 KB
testcase_17 AC 124 ms
50,408 KB
testcase_18 AC 124 ms
50,456 KB
testcase_19 AC 124 ms
50,460 KB
testcase_20 AC 123 ms
50,652 KB
testcase_21 AC 122 ms
50,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

const int mod = 1000000007;
long long dp[200005][30];
long long dp2[30];

inline long long modpow(long long a,long long b,long long m) {
    long long ans = 1;
    while(b) {
        if(b & 1) {
            (ans *= a) %= m;
        }
        (a *= a) %= m;
        b /= 2;
    }
    return ans;
}

int main() {
    string S;
    cin >> S;
    for(int i = 0; i < S.size(); i++) {
        int c = S[i]-'a';
        dp[i+1][c]++;
        dp[i+1][c] %= mod;
        dp2[c] += modpow(2,i,mod);
        dp2[c] %= mod;
        for(int j = 0; j < 26; j++) {
            dp[i+1][j] += dp[i][j];
            dp[i+1][j] %= mod;
            if(j == c) {
                dp[i+1][j] += dp[i][j];
                dp[i+1][j] %= mod;
            }
            else {
                dp[i+1][c] += dp[i][j];
                dp[i+1][c] %= mod;
                dp[i+1][c] += dp2[j];
                dp[i+1][c] %= mod;
            }
        }
    }
    long long ans = 0;
    for(int i = 0; i < 26; i++) {
        ans += dp[S.size()][i];
        ans %= mod;
    }
    cout << ans << endl;
}
0