목차

a^ib^jc^k

ps
링크acmicpc.net/…
출처BOJ
문제 번호15485
문제명a^ib^jc^k
레벨골드 2
분류

dp

시간복잡도O(n)
인풋사이즈n<=1,000,000
사용한 언어Python 3.11
제출기록33212KB / 204ms
최고기록204ms
해결날짜2023/07/17

풀이

코드

"""Solution code for "BOJ 15485. \(a^ib^jc^k\)".

- Problem link: https://www.acmicpc.net/problem/15485
- Solution link: http://www.teferi.net/ps/problems/boj/15485
"""

MOD = 1_000_000_007


def main():
    S = input()

    count_a = count_b = count_c = 0
    for c in S:
        if c == 'a':
            count_a = (count_a * 2 + 1) % MOD
        elif c == 'b':
            count_b = (count_b * 2 + count_a) % MOD
        elif c == 'c':
            count_c = (count_c * 2 + count_b) % MOD

    print(count_c)


if __name__ == '__main__':
    main()