Submission #2955903


Source Code Expand

Copy
S = gets.chomp
N = S.length

a = 0
ab = 0
ans = 0
all = 1

MOD = 10**9+7

N.times do |i|
    if S[i] == 'A'
        a += all
    elsif S[i] == 'B'
        ab += a
    elsif S[i] == 'C'
        ans += ab
    elsif S[i] == '?'
        ans = ans*3 + ab
        ab = ab*3 + a
        a = a*3 + all
        all *= 3
    end
    a %= MOD
    ab %= MOD
    ans %= MOD
    all %= MOD
end
puts ans

Submission Info

Submission Time
Task D - We Love ABC
User betrue12
Language Ruby (2.3.3)
Score 400
Code Size 416 Byte
Status
Exec Time 101 ms
Memory 2044 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 a01, a02, a03
All 400 / 400 a01, a02, a03, b04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23
Case Name Status Exec Time Memory
a01 8 ms 1788 KB
a02 8 ms 1788 KB
a03 8 ms 1788 KB
b04 8 ms 1788 KB
b05 8 ms 1788 KB
b06 8 ms 1788 KB
b07 8 ms 1788 KB
b08 8 ms 1788 KB
b09 8 ms 1788 KB
b10 76 ms 1916 KB
b11 101 ms 1916 KB
b12 59 ms 1916 KB
b13 58 ms 2044 KB
b14 57 ms 1916 KB
b15 58 ms 2044 KB
b16 58 ms 2044 KB
b17 58 ms 2044 KB
b18 18 ms 1788 KB
b19 8 ms 1788 KB
b20 20 ms 1788 KB
b21 74 ms 1916 KB
b22 73 ms 2044 KB
b23 64 ms 2044 KB