結果

問題 No.214 素数サイコロと合成数サイコロ (3-Medium)
ユーザー heno239heno239
提出日時 2020-08-15 14:18:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,864 ms / 3,000 ms
コード長 4,723 bytes
コンパイル時間 1,920 ms
コンパイル使用メモリ 125,428 KB
実行使用メモリ 16,000 KB
最終ジャッジ日時 2024-10-10 17:52:55
合計ジャッジ時間 9,884 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,864 ms
16,000 KB
testcase_01 AC 1,842 ms
15,104 KB
testcase_02 AC 1,852 ms
16,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod =1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);

ll mod_pow(ll x, ll n, ll m = mod) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * x % m;
		x = x * x % m; n >>= 1;
	}
	return res;
}
struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n % mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
	if (n == 0)return modint(1);
	modint res = (a * a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	while (b) {
		ll r = a % b; a = b; b = r;
	}
	return a;
}

struct kitamasa {
private:
	vector<ll> ori;
	int k;
public:
	kitamasa(vector<ll> d) {
		k = d.size();
		rep(i, k) {
			ori.push_back(d[i]);
		}
	}
	void plus1(vector<ll>& s) {
		vector<ll> ss;
		ss.push_back(s[k - 1] * ori[0]);
		rep1(i, k - 1) {
			ss.push_back((s[i - 1] + s[k - 1] * ori[i]) % mod);
		}
		rep(i, k)s[i] = ss[i];
	}
	void multi2(vector<ll>& s) {
		vector<ll> memo = s;
		vector<vector<ll>> v;
		rep(i, k) {
			plus1(s);
			v.push_back(s);
		}
		rep(i, k) {
			ll csum = 0;
			rep(j, k) {
				csum += memo[j] * v[j][i] % mod;
				csum %= mod;
			}
			s[i] = csum;
		}
	}
	vector<ll> calc(ll n) {
		n += k;
		vector<ll> s;
		s.push_back(1);
		rep(i, k - 1)s.push_back(0);
		ll cop = n; int cnt = 0;
		while (cop) {
			cnt++; cop >>= 1;
		}
		per(i, cnt - 1) {
			ll z = (ll)1 << i;
			multi2(s);
			if (n & z) {
				plus1(s);
			}
		}
		return s;
	}
};
vector<int> a = { 2,3,5,7,11,13 };
vector<int> b = { 4,6,8,9,10,12 };

modint dp1[3901][6];
modint sum1[3901];
modint dp2[3601][6];
modint sum2[3601];
modint dp[7501];
void solve() {
	ll n; cin >> n;
	int p, c; cin >> p >> c;
	dp1[0][0] = 1;
	rep(i, p) {
		per(j, 13 * i + 1) {
			per(k, 6) {
				for (int l = k; l < 6; l++) {
					dp1[j + a[l]][l] += dp1[j][k];
				}
				dp1[j][k] = 0;
			}
		}
	}
	dp2[0][0] = 1;
	rep(i, c) {
		per(j, 12*i + 1) {
			per(k, 6) {
				for (int l = k; l < 6; l++) {
					dp2[j + b[l]][l] += dp2[j][k];
				}
				dp2[j][k] = 0;
			}
		}
	}
	rep(i, 13 * p + 1) {
		rep(j, 6)sum1[i] += dp1[i][j];
	}
	rep(i, 12 * c + 1)rep(j, 6)sum2[i] += dp2[i][j];
	rep(i, 13 * p + 1)rep(j, 12 * c + 1)dp[i + j] += sum1[i] * sum2[j];




	int sup = 13 * p + 12 * c;
	vector<ll> ori(sup);
	rep(i, sup) {
		ori[i] = dp[sup-i];
	}
	kitamasa kt(ori);
	ll le = max((ll)0, (ll)n - sup);
	//cout << "?? " << le << "\n";
	vector<ll> s = kt.calc(le);
	int sz = min((ll)sup, n);
	vector<ll> val(sz);
	rep(i, sz) {
		val[i] = s.back();
		kt.plus1(s);
		//rep(j, s.size())cout << s[j] << " "; cout << "\n";
	}
	//cout << le << " " << s.back() << "\n";
	modint ans = 0;
	for (int i = sz; i < sz + sup; i++) {
		rep(j, sup+1) {
			int to = i - j;
			if (to >= 0 && to < sz) {
				ans += dp[j] * (modint)val[to];
			}
		}
	}
	/*rep(i, sup + 1)cout <<i<<" "<< sum1[i]<<" "<<sum2[i] << " "<<dp[i]<<"\n";
	rep(i, sz) {
		cout << val[i] << "\n";
	}*/
	cout << ans << "\n";
}





signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	//init_f();
	//init();
	//expr();
	//int t; cin >> t; rep(i, t)
	solve();
	return 0;
}
0