結果

問題 No.2147 ハノイの塔のおもちゃ
ユーザー ransewhaleransewhale
提出日時 2022-12-06 23:55:44
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 812 bytes
コンパイル時間 792 ms
コンパイル使用メモリ 79,820 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 12:38:30
合計ジャッジ時間 1,465 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

#pragma GCC optimize("O2")

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

std::string s;
ll sp[1111];

int main(void){
	int n,i;
	char t = 'A';
	ll ans = 0ll;
	std::cin >> n;
	for(i=1; i<=n; ++i){
		sp[i] = sp[i-1];
		mul_mod(sp[i],2ll); 
		add_mod(sp[i],1ll);
	}
	std::cin >> s;
	for(i=n-1; i>=0; --i){
		if(s[i] == t){
			continue;
		}
		t = 'A'+'B'+'C'-s[i]-t;
		add_mod(ans,1ll);
		add_mod(ans,sp[i]);
	}
	std::cout << ans << std::endl;
	return 0;
}
0