結果
| 問題 |
No.2147 ハノイの塔のおもちゃ
|
| コンテスト | |
| ユーザー |
Nachia
|
| 提出日時 | 2024-04-21 16:39:47 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 590 bytes |
| コンパイル時間 | 736 ms |
| コンパイル使用メモリ | 76,304 KB |
| 最終ジャッジ日時 | 2025-02-21 08:16:17 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 8 |
ソースコード
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <atcoder/modint>
using namespace std;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
using Modint = atcoder::modint1000000007;
int main(){
ios::sync_with_stdio(false); cin.tie(nullptr);
int N; cin >> N;
string S; cin >> S;
S += "A";
Modint ans = 0;
for(int i=N-1; i>=0; i--){
if(S[i] != S[i+1]){
ans += Modint(2).pow(i);
S[i] = S[i+1] ^ S[i] ^ 'A' ^ 'B' ^ 'C';
}
}
cout << ans.val() << endl;
return 0;
}
Nachia