結果

問題 No.1171 Runs in Subsequences
ユーザー daikisuyamadaikisuyama
提出日時 2020-08-15 09:31:40
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,065 bytes
コンパイル時間 242 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 555,776 KB
最終ジャッジ日時 2024-04-18 23:46:51
合計ジャッジ時間 13,483 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
52,352 KB
testcase_01 AC 43 ms
51,840 KB
testcase_02 AC 44 ms
52,528 KB
testcase_03 AC 44 ms
52,864 KB
testcase_04 AC 42 ms
52,736 KB
testcase_05 AC 43 ms
52,864 KB
testcase_06 AC 45 ms
52,224 KB
testcase_07 AC 46 ms
52,736 KB
testcase_08 AC 45 ms
52,608 KB
testcase_09 AC 42 ms
52,224 KB
testcase_10 AC 70 ms
69,504 KB
testcase_11 AC 72 ms
69,692 KB
testcase_12 AC 70 ms
69,376 KB
testcase_13 AC 73 ms
69,376 KB
testcase_14 AC 70 ms
69,376 KB
testcase_15 MLE -
testcase_16 MLE -
testcase_17 MLE -
testcase_18 MLE -
testcase_19 MLE -
testcase_20 MLE -
testcase_21 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

s=input()
n=len(s)
#dp[i][j]:=i文字目まで決めた時にアルファベットjになるような(文字列の個数,Runの個数)
#ペアにしてもつの珍しいけど、どちらもわからないと決まらないので
dp=[[[0,0] for i in range(26)] for i in range(n)]
mod=10**9+7
for i in range(n):
    d=ord(s[i])-97
    #新しく追加
    dp[i][d]=[1,1]
    if i==0:continue
    #選ばない場合(増えはしない)
    for j in range(26):
        dp[i][j][0]+=dp[i-1][j][0]
        dp[i][j][0]%=mod
        dp[i][j][1]+=dp[i-1][j][1]
        dp[i][j][1]%=mod
    #選ぶ場合(異なればその文字列数ぶんだけ増える)
    for j in range(26):
        if j==d:
            dp[i][j][0]+=dp[i-1][j][0]
            dp[i][j][0]%=mod
            dp[i][j][1]+=dp[i-1][j][1]
            dp[i][j][1]%=mod
        else:
            dp[i][d][0]+=dp[i-1][j][0]
            dp[i][d][0]%=mod
            dp[i][d][1]+=(dp[i-1][j][0]+dp[i-1][j][1])
            dp[i][d][1]%=mod
ans=0
for j in range(26):
    ans+=dp[n-1][j][1]
    ans%=mod
print(ans)
0