結果

問題 No.1171 Runs in Subsequences
ユーザー SalmonizeSalmonize
提出日時 2020-08-14 22:34:02
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 394 ms / 2,000 ms
コード長 1,196 bytes
コンパイル時間 388 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 46,792 KB
最終ジャッジ日時 2024-04-18 22:24:31
合計ジャッジ時間 6,363 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 167 ms
26,368 KB
testcase_01 AC 167 ms
26,368 KB
testcase_02 AC 164 ms
26,240 KB
testcase_03 AC 163 ms
26,112 KB
testcase_04 AC 163 ms
26,368 KB
testcase_05 AC 163 ms
26,240 KB
testcase_06 AC 173 ms
26,368 KB
testcase_07 AC 167 ms
26,368 KB
testcase_08 AC 166 ms
26,368 KB
testcase_09 AC 164 ms
26,240 KB
testcase_10 AC 172 ms
26,368 KB
testcase_11 AC 170 ms
26,240 KB
testcase_12 AC 172 ms
26,368 KB
testcase_13 AC 166 ms
26,368 KB
testcase_14 AC 172 ms
26,496 KB
testcase_15 AC 368 ms
36,492 KB
testcase_16 AC 369 ms
36,516 KB
testcase_17 AC 381 ms
37,060 KB
testcase_18 AC 394 ms
37,192 KB
testcase_19 AC 290 ms
46,792 KB
testcase_20 AC 285 ms
41,456 KB
testcase_21 AC 295 ms
39,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

readline = sys.stdin.buffer.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def modinv(x, mod):
    a, b = x, mod
    u, v = 1, 0
    while b:
        t = a // b
        a -= t * b; a, b = b, a
        u -= t * v; u, v = v, u
    return u % mod

mod = 10**9 + 7
n = 2 * 10 ** 5 + 10
pos = [1] * n
neg = [1] * n
for i in range(1, n):
    pos[i] = pos[i-1] * 2 % mod
neg[-1] = modinv(pos[-1], mod)
for j in range(n-2, -1, -1):
    neg[j] = neg[j+1] * 2 % mod


def solve():
    sig = 26
    s = [x - 97 for x in list(ns())]
    n = len(s)
    cur = 0
    g = [list() for _ in range(sig)]
    for i in range(n):
        g[s[i]].append(i)
    for x in range(sig):
        m = len(g[x])
        h = [neg[y] for y in g[x]]
        for j in range(m-2, -1, -1):
            h[j] += h[j+1]
        for i in range(m-1):
            # print(pow(2, n-1, mod) * pos[g[x][i]] * h[i+1] % mod)
            cur = (cur + pos[g[x][i]] * h[i+1]) % mod
    print((n - cur) * pow(2, n-1, mod) % mod)


    return

solve()
0