結果
| 問題 |
No.1171 Runs in Subsequences
|
| コンテスト | |
| ユーザー |
brthyyjp
|
| 提出日時 | 2021-10-08 02:25:24 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 317 ms / 2,000 ms |
| コード長 | 1,199 bytes |
| コンパイル時間 | 286 ms |
| コンパイル使用メモリ | 82,516 KB |
| 実行使用メモリ | 78,180 KB |
| 最終ジャッジ日時 | 2024-07-23 03:15:42 |
| 合計ジャッジ時間 | 3,789 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 18 |
ソースコード
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()
brthyyjp