Created
September 25, 2018 03:44
-
-
Save whatalnk/e8e5e67416853c81570c770fda83b319 to your computer and use it in GitHub Desktop.
AtCoder ABC #071 D
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = gets.chomp.to_i | |
s1 = gets.chomp | |
s2 = gets.chomp | |
MOD = 10**9 + 7 | |
ans = 1 | |
left = "" | |
right = "" | |
i = 0 | |
loop do | |
break if i >= n | |
if i == 0 | |
if s1[i] == s2[i] | |
ans *= 3 | |
left = "A" | |
i += 1 | |
else | |
ans *= 6 | |
left = "B" | |
i += 2 | |
end | |
else | |
if s1[i] == s2[i] | |
right = "A" | |
i += 1 | |
else | |
right = "B" | |
i += 2 | |
end | |
case left + right | |
when "AA" | |
ans *= 2 | |
when "AB" | |
ans *= 2 | |
when "BA" | |
ans *= 1 | |
when "BB" | |
ans *= 3 | |
end | |
ans %= MOD | |
left = right | |
end | |
end | |
puts ans % MOD |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment