結果

問題 No.1171 Runs in Subsequences
ユーザー stngstng
提出日時 2022-09-19 22:14:32
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 908 bytes
コンパイル時間 407 ms
コンパイル使用メモリ 10,960 KB
実行使用メモリ 12,984 KB
最終ジャッジ日時 2023-08-23 19:09:37
合計ジャッジ時間 4,746 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
12,240 KB
testcase_01 AC 16 ms
8,120 KB
testcase_02 AC 16 ms
7,976 KB
testcase_03 AC 17 ms
7,948 KB
testcase_04 AC 17 ms
8,016 KB
testcase_05 AC 16 ms
8,068 KB
testcase_06 AC 17 ms
7,912 KB
testcase_07 AC 17 ms
7,972 KB
testcase_08 AC 16 ms
7,992 KB
testcase_09 AC 16 ms
8,024 KB
testcase_10 AC 53 ms
7,984 KB
testcase_11 AC 52 ms
7,988 KB
testcase_12 AC 53 ms
7,980 KB
testcase_13 AC 52 ms
8,056 KB
testcase_14 AC 52 ms
7,964 KB
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

s = input()
ngs = len(s)
num = 26
dp = [[0]*2 for i in range(num)]
#dp[0][0] = 1

mod = 10**9+7

for i in range(ngs):
    idx = ord(s[i])-ord("a")
    dp_n = [[0]*2 for i in range(num)]
    dp_n[idx][0] += 1
    dp_n[idx][1] += 1
    #print(dp_n)
    for j in range(num):
        if j == idx:
            dp_n[idx][0] += dp[j][0]*2
            dp_n[idx][1] += dp[idx][1]*2
            dp_n[idx][0] %= mod
            dp_n[idx][1] %= mod
        elif dp[j][0] != 0:
            dp_n[idx][0] += dp[j][0]+dp[j][1]
            dp_n[idx][0] %= mod
            dp_n[idx][1] += dp[j][1]
            dp_n[idx][1] %= mod
            dp_n[j][0] = dp[j][0]
            dp_n[j][0] %= mod
            dp_n[j][1] = dp[j][1]
            dp_n[j][1] %= mod
        #else:
        #    dp_n[j] = dp[i][j]
    #print(dp_n)
    dp = dp_n[:]

ans = 0
#print(dp)
for i in range(num):
    ans += dp[i][0]
    ans %= mod

print(ans)
0