結果
問題 | No.2147 ハノイの塔のおもちゃ |
ユーザー | ぷら |
提出日時 | 2022-12-04 03:39:48 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 823 bytes |
コンパイル時間 | 2,563 ms |
コンパイル使用メモリ | 200,552 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-11 05:27:07 |
合計ジャッジ時間 | 2,690 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 8 |
ソースコード
#include <bits/stdc++.h> using namespace std; constexpr int mod = 1000000007; long long modpow(long long a,long long b) { long long ans = 1; while(b) { if(b & 1) { (ans *= a) %= mod; } (a *= a) %= mod; b /= 2; } return ans; } int main() { int N; string S; cin >> N >> S; int ans = 0; for(int i = N-1; i >= 0; i--) { if(S[i] != 'A') { ans += modpow(2,i); ans %= mod; for(int j = 0; j < i; j++) { if(S[j] != 'A' && S[j] != S[i]) { S[j] = 'A'; } else if(S[j] == 'A') { if(S[i] == 'C') S[j] = 'B'; else S[j] = 'C'; } } } } cout << ans << endl; }