結果

問題 No.1171 Runs in Subsequences
ユーザー kyort0nkyort0n
提出日時 2020-08-19 00:15:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 1,187 bytes
コンパイル時間 1,624 ms
コンパイル使用メモリ 163,332 KB
実行使用メモリ 46,080 KB
最終ジャッジ日時 2024-04-20 08:04:31
合計ジャッジ時間 2,821 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 4 ms
5,376 KB
testcase_06 AC 4 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 4 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 69 ms
44,392 KB
testcase_16 AC 67 ms
43,888 KB
testcase_17 AC 71 ms
46,004 KB
testcase_18 AC 70 ms
46,004 KB
testcase_19 AC 71 ms
45,824 KB
testcase_20 AC 71 ms
46,080 KB
testcase_21 AC 71 ms
45,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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