結果

問題 No.1171 Runs in Subsequences
ユーザー rlangevinrlangevin
提出日時 2023-08-18 12:04:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 183 ms / 2,000 ms
コード長 392 bytes
コンパイル時間 504 ms
コンパイル使用メモリ 86,848 KB
実行使用メモリ 91,096 KB
最終ジャッジ日時 2023-08-18 12:04:56
合計ジャッジ時間 3,838 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
71,248 KB
testcase_01 AC 70 ms
71,304 KB
testcase_02 AC 68 ms
71,116 KB
testcase_03 AC 68 ms
71,464 KB
testcase_04 AC 63 ms
71,000 KB
testcase_05 AC 64 ms
71,264 KB
testcase_06 AC 65 ms
71,048 KB
testcase_07 AC 63 ms
71,220 KB
testcase_08 AC 62 ms
71,260 KB
testcase_09 AC 64 ms
70,960 KB
testcase_10 AC 64 ms
71,264 KB
testcase_11 AC 65 ms
70,956 KB
testcase_12 AC 63 ms
71,104 KB
testcase_13 AC 64 ms
71,116 KB
testcase_14 AC 64 ms
71,396 KB
testcase_15 AC 183 ms
88,312 KB
testcase_16 AC 113 ms
87,148 KB
testcase_17 AC 114 ms
91,044 KB
testcase_18 AC 118 ms
90,856 KB
testcase_19 AC 118 ms
91,096 KB
testcase_20 AC 119 ms
90,960 KB
testcase_21 AC 121 ms
91,076 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

S = list(input())
N = len(S)
for i in range(N):
    S[i] = ord(S[i]) - ord("a")

mod = 10 ** 9 + 7
two = [1] * (N + 1)
for i in range(N):
    two[i + 1] = two[i] * 2
    two[i + 1] %= mod

L = [0] * 26
sm = 0
ans = pow(2, N, mod) - 1
for i, s in enumerate(S):
    now = sm - L[s]
    ans += now * two[N - 1 - i]
    ans %= mod
    L[s] += two[i]
    sm += two[i]
    sm %= mod

print(ans%mod)
0