結果

問題 No.1811 EQUIV Ten
ユーザー startcppstartcpp
提出日時 2022-01-15 00:44:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 762 bytes
コンパイル時間 3,072 ms
コンパイル使用メモリ 140,036 KB
実行使用メモリ 9,888 KB
最終ジャッジ日時 2024-04-30 19:32:32
合計ジャッジ時間 3,699 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,720 KB
testcase_01 AC 3 ms
9,660 KB
testcase_02 AC 3 ms
9,848 KB
testcase_03 AC 4 ms
9,792 KB
testcase_04 AC 4 ms
9,668 KB
testcase_05 AC 3 ms
9,688 KB
testcase_06 AC 4 ms
9,748 KB
testcase_07 AC 4 ms
9,776 KB
testcase_08 AC 4 ms
9,888 KB
testcase_09 AC 4 ms
9,688 KB
testcase_10 AC 4 ms
9,636 KB
testcase_11 AC 7 ms
9,664 KB
testcase_12 AC 6 ms
9,772 KB
testcase_13 AC 7 ms
9,672 KB
testcase_14 AC 7 ms
9,652 KB
testcase_15 AC 7 ms
9,692 KB
testcase_16 AC 3 ms
9,736 KB
testcase_17 AC 4 ms
9,804 KB
testcase_18 AC 4 ms
9,736 KB
testcase_19 AC 4 ms
9,724 KB
testcase_20 AC 3 ms
9,844 KB
testcase_21 AC 4 ms
9,660 KB
testcase_22 AC 3 ms
9,692 KB
testcase_23 AC 5 ms
9,716 KB
testcase_24 AC 3 ms
9,660 KB
testcase_25 AC 3 ms
9,748 KB
testcase_26 AC 4 ms
9,780 KB
testcase_27 AC 4 ms
9,748 KB
testcase_28 AC 4 ms
9,680 KB
testcase_29 AC 3 ms
9,672 KB
testcase_30 AC 7 ms
9,804 KB
testcase_31 AC 3 ms
9,696 KB
testcase_32 AC 4 ms
9,656 KB
testcase_33 AC 3 ms
9,548 KB
testcase_34 AC 7 ms
9,708 KB
testcase_35 AC 4 ms
9,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//2進数を考えると次の問題に落とせる。
//・N桁の0,1列であって、ある連続する4桁が"1010"になっているものはいくつあるか?
//これは動的計画法で簡単に解くことができる。余事象を数えると実装が楽。
#include <iostream>
#include <atcoder/all>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;
using namespace atcoder;
using mint = modint1000000007;

int n;
mint dp[200001][8];

int main() {
	int i, j, k;
	
	cin >> n;
	dp[0][0] = 1;
	rep(i, n) {
		rep(j, 8) {
			rep(k, 2) {
				if (2 * j + k == 10) continue;
				dp[i + 1][(j % 4) * 2 + k] += dp[i][j];
			}
		}
	}
	
	mint ans = pow_mod(2, n, 1000000007);
	rep(i, 8) ans -= dp[n][i];
	
	cout << ans.val() << endl;
	return 0;
}
0