結果

問題 No.1171 Runs in Subsequences
ユーザー DriceDrice
提出日時 2020-08-14 21:42:57
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 1,028 bytes
コンパイル時間 321 ms
コンパイル使用メモリ 34,176 KB
実行使用メモリ 47,744 KB
最終ジャッジ日時 2024-04-18 21:20:08
合計ジャッジ時間 1,411 ms
ジャッジサーバーID
(参考情報)
judge2 / 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 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 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 37 ms
45,952 KB
testcase_16 AC 37 ms
45,568 KB
testcase_17 AC 39 ms
47,616 KB
testcase_18 AC 37 ms
47,744 KB
testcase_19 AC 36 ms
47,744 KB
testcase_20 AC 37 ms
47,744 KB
testcase_21 AC 38 ms
47,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<cstring>
const long long mod = 1e9+7;
char s[200005];
long long f[200005][28];

long long power(long long a,long long b){
    long long res = 1;
    while(b){
        if(b&1) res = res*a%mod;
        a = a*a%mod;
        b /= 2;
    }
    return res;
}

int main(){
    scanf("%s",s+1);
    int n = strlen(s+1);
    long long ans = 0;
    f[0][0] = 1;
    for(int i = 1; i <= 26; i++) f[0][i] = 0;
    long long sum = f[0][0];
    for(int i = 1; i <= n; i++){
        int u = s[i]-'a'+1;
        long long newSum = 0;
        for(int j = 0; j <= 26; j++){
            if(j==u) f[i][j] = (f[i-1][j]+sum)%mod;
            else f[i][j] = f[i-1][j];
            newSum += f[i][j]; if(newSum>=mod) newSum -= mod;
        }
        long long way = sum-f[i-1][u];
        if(way<0) way += mod;
        long long add = way*power(2,n-i)%mod;
        //printf("way = %lld, sum = %lld\n",way,sum);
        ans += add; if(ans>=mod) ans -= mod;
        sum = newSum;
    }
    printf("%lld\n",ans);
    return 0;
}
0