結果
| 問題 |
No.214 素数サイコロと合成数サイコロ (3-Medium)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-09-30 17:07:54 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 456 ms / 3,000 ms |
| コード長 | 2,094 bytes |
| コンパイル時間 | 1,389 ms |
| コンパイル使用メモリ | 166,656 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-19 18:11:23 |
| 合計ジャッジ時間 | 3,370 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 |
ソースコード
#include <bits/stdc++.h>
#define GET_MACRO(a, b, c, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define rep2(i, a) rep3 (i, 0, a)
#define rep3(i, a, b) for (int i = (a); i < (b); i++)
#define repr(...) GET_MACRO(__VA_ARGS__, repr3, repr2)(__VA_ARGS__)
#define repr2(i, a) repr3 (i, 0, a)
#define repr3(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define chmin(a, b) ((b) < a && (a = (b), true))
#define chmax(a, b) (a < (b) && (a = (b), true))
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
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;
}
repr (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) {
if (b & 1) res = mul(res, p, a);
p = mul(p, p, a);
b /= 2;
}
return res;
}
// b[n+k]=a[0]b[n]+...+a[k-1]b[n+k-1]
ll calc(vector<ll> a, vector<ll> b, ll n) {
a.insert(a.begin(), 0);
b.insert(b.begin(), 0);
a = pow(a, n + 1);
ll res = 0;
rep (i, a.size()) {
(res += a[i] * b[i]) %= mod;
}
return res;
}
};
ll dp[2][55][2020];
ll way[2020];
void calc(ll dp[55][2020], ll n, vector<int> dice) {
dp[0][0] = 1;
rep (k, dice.size()) {
rep (i, n) {
rep (j, 1010) {
(dp[i + 1][j + dice[k]] += dp[i][j]) %= mod;
}
}
}
}
template<class T>
ostream &operator <<(ostream &os, const vector<T> &v) {
rep (i, v.size()) {
if (i) os << " ";
os << v[i];
}
return os;
}
int main() {
ll N, P, C;
cin >> N >> P >> C;
calc(dp[0], P, {2, 3, 5, 7, 11, 13});
calc(dp[1], C, {4, 6, 8, 9, 10, 12});
rep (i, 1010) {
rep (j, 1010) {
(way[i + j] += dp[0][P][i] * dp[1][C][j]) %= mod;
}
}
ll K = P * 13 + C * 12 + 1;
vector<ll> a(K), b(K);
rep (i, K) {
a[i] = way[K - i];
b[i] = 1;
}
Kitamasa ktms;
cout << ktms.calc(a, b, N + K - 1) << endl;
return 0;
}