結果
問題 | No.2147 ハノイの塔のおもちゃ |
ユーザー |
![]() |
提出日時 | 2022-12-04 00:20:45 |
言語 | C (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 799 bytes |
コンパイル時間 | 439 ms |
コンパイル使用メモリ | 29,696 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-11 02:54:41 |
合計ジャッジ時間 | 1,031 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 8 |
ソースコード
#include <stdio.h> void func (int n, char *s, char t, long long *ans, long long *pow2, long long mod_num) { if (n < 0) { return; } if (s[n] == t) { func(n-1, s, t, ans, pow2, mod_num); } else { char nxt = 'A'; while (nxt == s[n] || nxt == t) { nxt += (char)1; } func(n-1, s, nxt, ans, pow2, mod_num); *ans += pow2[n]; *ans %= mod_num; } return; } int main () { int n = 0; char s[1001] = ""; int res = 0; long long ans = 0LL; long long mod_num = 1000000007LL; long long pow2[1001] = {}; res = scanf("%d", &n); res = scanf("%s", s); pow2[0] = 1LL; for (int i = 0; i < n; i++) { pow2[i+1] = (2LL*pow2[i])%mod_num; } func(n-1, s, 'A', &ans, pow2, mod_num); printf("%lld\n", ans); return 0; }