結果

問題 No.213 素数サイコロと合成数サイコロ (3-Easy)
ユーザー pekempeypekempey
提出日時 2015-09-07 20:52:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 848 ms / 3,000 ms
コード長 2,192 bytes
コンパイル時間 1,565 ms
コンパイル使用メモリ 154,488 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-26 10:02:05
合計ジャッジ時間 4,630 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 848 ms
4,384 KB
testcase_01 AC 778 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < (a); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define repr(i, a) for (int i = (a) - 1; i >= 0; i--)
#define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--)
using namespace std;
typedef long long ll;

const ll mod = 1e9 + 7;

typedef vector<ll> vec;
typedef vector<vec> mat;
mat mul(mat &A, mat &B) {
	mat res(A.size(), vec(B[0].size()));
	rep (i, A.size()) rep (j, B[0].size()) rep (k, A[0].size()) {
		(res[i][j] += A[i][k] * B[k][j]) %= mod;
	}
	return res;
}
mat pow(mat A, ll b) {
	mat res(A.size(), vec(A.size()));
	rep (i, A.size()) res[i][i] = 1;
	while (b) {
		if (b & 1) res = mul(res, A);
		A = mul(A, A);
		b /= 2;
	}
	return res;
}

struct Kitamasa {
	vector<ll> mul(vector<ll> &a, vector<ll> &b, vector<ll> &c) {
		int k = a.size();
		vector<ll> res(k * 2);
		rep (i, k) rep (j, k) {
			(res[i + j] += a[i] * b[j]) %= mod;
		}
		repr2 (i, k, k * 2) rep (j, k) {
			(res[i - j - 1] += c[k - j - 1] * res[i]) %= mod;
		}
		res.resize(k);
		return res;
	}
	vector<ll> pow(vector<ll> &a, ll b) {
		vector<ll> p(a.size()), res(a.size());
		p[1] = res[0] = 1;
		while (b > 0) {
			if (b & 1) res = mul(res, p, a);
			p = mul(p, p, a);
			b /= 2;
		}
		return res;
	}
	ll calc(vector<ll> a, vector<ll> b, ll n) {
		a = pow(a, n);
		ll res = 0;
		rep (i, a.size()) {
			(res += a[i] * b[i]) %= mod;
		}
		return res;
	}
};

void calc(ll dp[6][200], ll n, vector<int> dice) {
	dp[0][0] = 1;	
	rep (k, dice.size()) {
		rep (i, n) {
			rep (j, 200) {
				int next = j + dice[k];
				if (next < 200) {
					(dp[i + 1][next] += dp[i][j]) %= mod;
				}
			}
		}
	}
}

ll dpP[6][200], dpC[6][200];

int main() {
	ll N, P, C;
	cin >> N >> P >> C;
	calc(dpP, P, {2, 3, 5, 7, 11, 13});
	calc(dpC, C, {4, 6, 8, 9, 10, 12});
	vector<int> num(200);
	rep (i, 200) {
		rep (j, 200) {
			if (i + j < 200) {
				(num[i + j] += dpP[P][i] * dpC[C][j]) %= mod;
			}
		}
	}
	const int n = 13 * 5 + 12 * 5 + 2;
	mat A(n, vec(n));
	rep (i, n - 1) {
		A[i][i + 1] = 1;
	}
	rep (i, n) {
		A[i][0] = num[i + 1];
	}
	A = pow(A, N);
	ll ans = 0;
	rep (i, n) {
		ans += A[i][0];	
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}
0