結果

問題 No.2147 ハノイの塔のおもちゃ
ユーザー hotman78hotman78
提出日時 2022-12-04 10:23:48
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 376 bytes
コンパイル時間 529 ms
コンパイル使用メモリ 82,456 KB
実行使用メモリ 65,536 KB
最終ジャッジ日時 2024-04-19 18:00:35
合計ジャッジ時間 1,592 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
51,840 KB
testcase_01 AC 35 ms
52,096 KB
testcase_02 AC 35 ms
51,584 KB
testcase_03 AC 34 ms
51,712 KB
testcase_04 AC 35 ms
51,968 KB
testcase_05 AC 36 ms
52,480 KB
testcase_06 AC 44 ms
60,416 KB
testcase_07 AC 54 ms
65,536 KB
testcase_08 AC 35 ms
52,096 KB
testcase_09 WA -
testcase_10 AC 50 ms
64,896 KB
testcase_11 AC 50 ms
64,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

dp=[0,0,0]
n=int(input())
s=input()
p2=1
for i in range(n):
    dp2=[0,0,0]
    for j in range(3):
        if ord(s[i])==(ord('A')+j):
            dp2[j]=min(dp[j],dp[(j+1)%3]+p2,dp[(j+2)%3]+p2)
        else:
            dp2[j]=min(dp[j]+p2*2+1,dp[ord(s[i])-ord('A')]+p2*2+1,dp[3-j-(ord(s[i])-ord('A'))]+p2+1)
    dp=dp2
    if i!=0:
        p2=p2*2+1
print(dp[0]%1000000007)
0