結果

問題 No.1171 Runs in Subsequences
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2020-08-14 22:00:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 237 ms / 2,000 ms
コード長 676 bytes
コンパイル時間 365 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 76,416 KB
最終ジャッジ日時 2024-04-18 21:47:51
合計ジャッジ時間 3,262 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
51,712 KB
testcase_01 AC 40 ms
52,096 KB
testcase_02 AC 35 ms
52,096 KB
testcase_03 AC 38 ms
57,088 KB
testcase_04 AC 34 ms
52,224 KB
testcase_05 AC 34 ms
51,840 KB
testcase_06 AC 36 ms
51,968 KB
testcase_07 AC 38 ms
56,576 KB
testcase_08 AC 44 ms
56,832 KB
testcase_09 AC 35 ms
52,224 KB
testcase_10 AC 47 ms
60,160 KB
testcase_11 AC 53 ms
60,160 KB
testcase_12 AC 50 ms
60,544 KB
testcase_13 AC 52 ms
61,056 KB
testcase_14 AC 54 ms
60,288 KB
testcase_15 AC 219 ms
76,288 KB
testcase_16 AC 224 ms
76,416 KB
testcase_17 AC 237 ms
76,288 KB
testcase_18 AC 230 ms
76,416 KB
testcase_19 AC 212 ms
76,032 KB
testcase_20 AC 214 ms
76,288 KB
testcase_21 AC 207 ms
76,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

https://yukicoder.me/problems/no/1171

runが増えるのは、新たな文字を追加する場合
入れる・入れないを選べるので

dp[i][最後の文字] = 現在門戸を開いている数
同じ文字を重ねて置いた場合、門戸は増えるが連は増えない

"""

from sys import stdin
S = stdin.readline()
S = S[:-1]

alp = "abcdefghijklmnopqrstuvwxyz"
ad = {}
for i in range(26):
    ad[alp[i]] = i

dp = [0] * 27
dp[-1] = 1
mod = 10**9+7

ans = 0

for loop in range(len(S)):
    i = S[loop]

    nsum = sum(dp) - dp[ad[i]]
    ans += nsum * pow(2,len(S)-loop-1,mod)
    ans %= mod
    dp[ad[i]] += sum(dp)
    dp[ad[i]] %= mod

print (ans)
0