結果

問題 No.1171 Runs in Subsequences
ユーザー brthyyjpbrthyyjp
提出日時 2021-10-08 02:25:24
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 346 ms / 2,000 ms
コード長 1,199 bytes
コンパイル時間 296 ms
コンパイル使用メモリ 87,304 KB
実行使用メモリ 79,284 KB
最終ジャッジ日時 2023-09-30 09:12:48
合計ジャッジ時間 4,869 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,368 KB
testcase_01 AC 72 ms
71,360 KB
testcase_02 AC 73 ms
71,236 KB
testcase_03 AC 73 ms
71,448 KB
testcase_04 AC 72 ms
71,484 KB
testcase_05 AC 74 ms
71,488 KB
testcase_06 AC 74 ms
71,488 KB
testcase_07 AC 72 ms
71,516 KB
testcase_08 AC 74 ms
71,340 KB
testcase_09 AC 73 ms
71,164 KB
testcase_10 AC 88 ms
76,460 KB
testcase_11 AC 88 ms
76,388 KB
testcase_12 AC 88 ms
76,468 KB
testcase_13 AC 86 ms
76,336 KB
testcase_14 AC 91 ms
76,524 KB
testcase_15 AC 343 ms
78,988 KB
testcase_16 AC 331 ms
79,284 KB
testcase_17 AC 346 ms
78,952 KB
testcase_18 AC 343 ms
79,064 KB
testcase_19 AC 340 ms
78,968 KB
testcase_20 AC 344 ms
78,856 KB
testcase_21 AC 342 ms
78,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 10**9+7

def main():

    S = str(input())
    S = [ord(c)-ord('a') for c in S]
    n = len(S)
    dp = [[0, 0] for i in range(26)]
    #dp[c][0]: 最後がcの文字列の個数
    #dp[c][1]: 最後がcの文字列の連の和
    ans = 0
    for i, c in enumerate(S):
        if i == 0:
            dp[c][0] = 1
            dp[c][1] = 1
            continue
        nx = [[0, 0] for j in range(26)]
        nx[c][0] = 1
        nx[c][1] = 1
        # i番目の文字列を選ばない場合
        for j in range(26):
            nx[j][0] += dp[j][0]
            nx[j][0] %= mod
            nx[j][1] += dp[j][1]
            nx[j][1] %= mod
        # i番目の文字列を選ぶ場合
        for j in range(26):
            if j == c:
                nx[j][0] += dp[j][0]
                nx[j][0] %= mod
                nx[j][1] += dp[j][1]
                nx[j][1] %= mod
            else:
                nx[c][0] += dp[j][0]
                nx[c][0] %= mod
                nx[c][1] += dp[j][0]+dp[j][1]
                nx[c][1] %= mod
        dp = nx
    ans = 0
    for j in range(26):
        ans += dp[j][1]
        ans %= mod
    print(ans)

if __name__ == '__main__':
    main()
0