結果

問題 No.1171 Runs in Subsequences
ユーザー ぷらぷら
提出日時 2021-03-14 23:12:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 109 ms / 2,000 ms
コード長 1,117 bytes
コンパイル時間 1,522 ms
コンパイル使用メモリ 163,840 KB
実行使用メモリ 50,660 KB
最終ジャッジ日時 2024-04-24 04:31:33
合計ジャッジ時間 3,235 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 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 3 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 104 ms
49,024 KB
testcase_16 AC 105 ms
48,368 KB
testcase_17 AC 108 ms
50,532 KB
testcase_18 AC 107 ms
50,660 KB
testcase_19 AC 109 ms
50,556 KB
testcase_20 AC 109 ms
50,536 KB
testcase_21 AC 108 ms
50,660 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