結果

問題 No.213 素数サイコロと合成数サイコロ (3-Easy)
ユーザー pekempeypekempey
提出日時 2015-09-04 15:08:50
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 380 ms / 3,000 ms
コード長 1,618 bytes
コンパイル時間 1,448 ms
コンパイル使用メモリ 147,360 KB
実行使用メモリ 5,444 KB
最終ジャッジ日時 2023-09-26 04:19:42
合計ジャッジ時間 2,748 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 380 ms
5,444 KB
testcase_01 AC 346 ms
5,416 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;
const int maxdim = 256;
int dim;
typedef ll mat[maxdim][maxdim];
mat M0, M1, M2, M3;

void matmul(mat A, mat B, mat res) {
	memset(M0, 0, sizeof(M0));
	rep (i, dim) rep (k, dim) rep (j, dim) {
		(M0[i][j] += A[i][k] * B[k][j]) %= mod;
	}
	memcpy(res, M0, sizeof(M0));
}

void matpow(mat A, ll b, mat res) {
	memcpy(M1, A, sizeof(M1));
	rep (i, dim) rep (j, dim) M2[i][j] = i == j;
	while (b > 0) {
		if (b & 1) matmul(M1, M2, M2);
		matmul(M1, M1, M1);
		b >>= 1;
	}
	memcpy(res, M2, sizeof(M2));
}

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

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;
				}
			}
		}
	}
}

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;
			}
		}
	}
	mat A;
	memset(A, 0, sizeof(A));
	const int n = 13 * 5 + 12 * 5 + 2;
	dim = n;
	rep (i, n - 1) {
		A[i][i + 1] = 1;
	}
	rep (i, n) {
		A[i][0] = num[i + 1];
	}
	matpow(A, N, A);
	ll ans = 0;
	rep (i, n) {
		ans += A[i][0];	
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}
0