結果
問題 | No.2147 ハノイの塔のおもちゃ |
ユーザー | Nzt3 |
提出日時 | 2022-12-18 02:14:12 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 426 bytes |
コンパイル時間 | 2,833 ms |
コンパイル使用メモリ | 200,944 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-17 10:25:52 |
合計ジャッジ時間 | 2,893 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 8 |
ソースコード
#include<bits/stdc++.h> using namespace std; const int mod=1e9+7; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin>>N; string S; cin>>S; long long ans=0; long long beki[N+1]; beki[0]=1; for(int i=1;i<=N;i++)beki[i]=beki[i-1]*2%mod; int m=0; for(int i=N-1;i>=0;i--){ if(S[i]-'A'!=m){ ans=(ans+beki[i])%mod; m=3^m^(S[i]-'A'); } } cout<<(ans+mod)%mod<<'\n'; }