結果

問題 No.1171 Runs in Subsequences
ユーザー auauaauaua
提出日時 2020-08-14 23:06:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 184 ms / 2,000 ms
コード長 1,746 bytes
コンパイル時間 2,003 ms
コンパイル使用メモリ 169,164 KB
実行使用メモリ 100,480 KB
最終ジャッジ日時 2024-04-18 22:59:11
合計ジャッジ時間 3,802 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 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 3 ms
5,376 KB
testcase_11 AC 3 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 176 ms
96,860 KB
testcase_16 AC 176 ms
95,592 KB
testcase_17 AC 183 ms
100,408 KB
testcase_18 AC 184 ms
100,272 KB
testcase_19 AC 121 ms
100,352 KB
testcase_20 AC 131 ms
100,352 KB
testcase_21 AC 129 ms
100,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef complex<double> comp;
const ll inf=1e9+7;
const ll mod=2e5+3;
const int MAX=1000010;

signed main(){
    string s;cin>>s;
    ll n=s.size();
    vector<vector<ll> >dp(n+1,vector<ll>(26,-1));
    dp[0][26]=0;
    vector<vector<ll> >x(n+1,vector<ll>(26,-1));
    rep(i,n){
        ll c=s[i]-'a';
        rep(j,26){
            if(x[i][j]<0)continue;
            if(x[i+1][j]<0)x[i+1][j]=0;
            if(x[i+1][c]<0)x[i+1][c]=0;
            x[i+1][j]=(x[i+1][j]+x[i][j])%inf;
            if(j!=c)x[i+1][c]=(x[i+1][c]+x[i][j]%inf)%inf;
            else x[i+1][c]=(x[i+1][c]+x[i][c])%inf;
        }
        if(x[i+1][c]<0)x[i+1][c]=0;
        x[i+1][c]=(x[i+1][c]+1)%inf;
    }
    
    rep(i,n){
        ll c=s[i]-'a';
        rep(j,26){
            if(dp[i][j]<0)continue;
            if(dp[i+1][j]<0)dp[i+1][j]=0;
            if(dp[i+1][c]<0)dp[i+1][c]=0;
            dp[i+1][j]=(dp[i+1][j]+dp[i][j])%inf;
            if(j!=c)dp[i+1][c]=(dp[i+1][c]+dp[i][j]+x[i][j])%inf;
            else dp[i+1][c]=(dp[i+1][c]+dp[i][c])%inf;
        }
        if(dp[i+1][c]<0)dp[i+1][c]=0;
        dp[i+1][c]=(dp[i+1][c]+1)%inf;
    }
    ll ans=0;
    rep(i,26){
        if(dp[n][i]<0)continue;
        ans=(ans+dp[n][i])%inf;
        //cout<<dp[n][i]<<endl;
    }
    cout<<ans<<endl;
}
0