結果

問題 No.1171 Runs in Subsequences
ユーザー daikisuyamadaikisuyama
提出日時 2020-08-15 09:39:32
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 237 ms / 2,000 ms
コード長 1,043 bytes
コンパイル時間 422 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 76,800 KB
最終ジャッジ日時 2024-04-18 23:48:03
合計ジャッジ時間 3,374 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,608 KB
testcase_01 AC 41 ms
52,096 KB
testcase_02 AC 41 ms
52,480 KB
testcase_03 AC 41 ms
52,864 KB
testcase_04 AC 43 ms
52,352 KB
testcase_05 AC 41 ms
52,608 KB
testcase_06 AC 41 ms
52,480 KB
testcase_07 AC 42 ms
52,864 KB
testcase_08 AC 42 ms
52,480 KB
testcase_09 AC 42 ms
52,224 KB
testcase_10 AC 59 ms
63,616 KB
testcase_11 AC 60 ms
63,488 KB
testcase_12 AC 60 ms
63,744 KB
testcase_13 AC 60 ms
63,360 KB
testcase_14 AC 60 ms
63,488 KB
testcase_15 AC 228 ms
76,288 KB
testcase_16 AC 227 ms
76,544 KB
testcase_17 AC 236 ms
76,248 KB
testcase_18 AC 237 ms
76,544 KB
testcase_19 AC 198 ms
76,280 KB
testcase_20 AC 232 ms
76,416 KB
testcase_21 AC 234 ms
76,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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