結果

問題 No.2147 ハノイの塔のおもちゃ
ユーザー tassei903tassei903
提出日時 2022-12-09 19:16:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 686 bytes
コンパイル時間 192 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 61,824 KB
最終ジャッジ日時 2024-04-22 19:15:17
合計ジャッジ時間 1,315 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
52,608 KB
testcase_01 AC 38 ms
52,608 KB
testcase_02 AC 38 ms
52,480 KB
testcase_03 AC 38 ms
52,096 KB
testcase_04 AC 38 ms
52,480 KB
testcase_05 AC 39 ms
52,352 KB
testcase_06 AC 45 ms
59,392 KB
testcase_07 AC 49 ms
61,184 KB
testcase_08 AC 38 ms
52,224 KB
testcase_09 AC 38 ms
52,352 KB
testcase_10 AC 50 ms
61,824 KB
testcase_11 AC 48 ms
61,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
#input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES")
no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO")
#######################################################################
n = ni()
s = [ord(i)-65 for i in input()]
dp = [1] * 3
dp[s[0]] = 0
mod = 10**9+7
for i in range(1,n):
    ndp = [0] * 3
    ndp, dp = dp, ndp
    for j in range(3):
        if j == s[i]:
            dp[j] = ndp[j]
        else:
            dp[j] = ndp[(-j-s[i])%3]+pow(2,i,mod)
            dp[j] %= mod
    #print(dp)
print(dp[0])
0