結果
問題 | No.214 素数サイコロと合成数サイコロ (3-Medium) |
ユーザー | fumiphys |
提出日時 | 2019-10-05 19:40:52 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 5,533 bytes |
コンパイル時間 | 1,816 ms |
コンパイル使用メモリ | 175,600 KB |
実行使用メモリ | 9,472 KB |
最終ジャッジ日時 | 2024-10-06 22:06:28 |
合計ジャッジ時間 | 7,531 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | RE | - |
testcase_02 | RE | - |
ソースコード
// includes #include <bits/stdc++.h> using namespace std; // macros #define pb emplace_back #define mk make_pair #define FOR(i, a, b) for(int i=(a);i<(b);++i) #define rep(i, n) FOR(i, 0, n) #define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--) #define irep(itr, st) for(auto itr = (st).begin(); itr != (st).end(); ++itr) #define irrep(itr, st) for(auto itr = (st).rbegin(); itr != (st).rend(); ++itr) #define all(x) (x).begin(),(x).end() #define sz(x) ((int)(x).size()) #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) #define bit(n) (1LL<<(n)) // functions template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;} template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;} template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;} template <typename T> ostream &operator<<(ostream &os, const vector<T>& vec){for(int i = 0; i < vec.size(); i++){ os << vec[i]; if(i + 1 != vec.size())os << " ";} return os;} template <typename T> ostream &operator<<(ostream &os, const set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;} template <typename T> ostream &operator<<(ostream &os, const unordered_set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;} template <typename T> ostream &operator<<(ostream &os, const multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;} template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;} template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){os << p.first << " " << p.second; return os;} template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << itr->first << ":" << itr->second; auto titr = itr; if(++titr != mp.end())os << " "; } return os;} template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << itr->first << ":" << itr->second; auto titr = itr; if(++titr != mp.end())os << " "; } return os;} // types using ll = long long int; using P = pair<int, int>; // constants const int inf = 1e9; const ll linf = 1LL << 50; const double EPS = 1e-10; const int mod = 1000000007; const int dx[4] = {-1, 0, 1, 0}; const int dy[4] = {0, -1, 0, 1}; // io struct fast_io{ fast_io(){ios_base::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20);} } fast_io_; const int MOD = mod; struct Kitamasa{ int k; vector<long long> a, d; Kitamasa(vector<long long> a, vector<long long> d): a(a), d(d){ k = a.size(); } vector<long long> mul(vector<long long> &x, vector<long long> &y){ vector<long long> t(2 * k, 0); for(int i = 0; i < k; i++){ for(int j = 0; j < k; j++){ (t[i+j] += x[i] * y[j] % MOD) %= MOD; } } for(int i = 2*k-2; i >= k; i--){ for(int j = 1; j <= k; j++){ (t[i-j] += d[k-j] * t[i] % MOD) %= MOD; } } t.resize(k); return t; } vector<long long> calc_coeff(long long n){ vector<long long> p(k, 0), v(k, 0); p[0] = v[1] = 1; while(n){ if(n % 2)p = mul(p, v); v = mul(v, v); n /= 2; } return p; } long long calc(long long n){ vector<long long> c = calc_coeff(n); long long res = 0; for(int i = 0; i < k; i++)res = (res + a[i] * c[i] % MOD) % MOD; return res; } }; int a[6] = {2, 3, 5, 7, 11, 13}; int b[6] = {4, 6, 8, 9, 10, 12}; ll d1[1301], d2[1301], nex[1301]; ll dp1[7][51][1301], dp2[7][51][1301]; ll C[1301], CS[1301]; int main(int argc, char const* argv[]) { ll n; int p, c; cin >> n >> p >> c; dp1[0][0][0] = 1; rep(i, 6){ rep(j, p + 1){ rep(k, 1301){ rep(l, j + 1){ if(k-l*a[i]>=0)(dp1[i+1][j][k] += dp1[i][j-l][k-l*a[i]]) %= mod; } } } } dp2[0][0][0] = 1; rep(i, 6){ rep(j, c + 1){ rep(k, 1301){ rep(l, j + 1){ if(k-l*b[i]>=0)(dp2[i+1][j][k] += dp2[i][j-l][k-l*b[i]]) %= mod; } } } } rep(i, 1301)d1[i] = dp1[6][p][i]; rep(i, 1301)d2[i] = dp2[6][c][i]; FOR(i, 1, 1301){ rep(j, i + 1){ (C[i] += d1[j] * d2[i-j] % mod) %= mod; } } rrep(i, 1301){ CS[i] = C[i] + (i < 1300 ? CS[i+1]: 0); } vector<ll> A(2601, 0); A[0] = 1; vector<ll> B(1300); rep(i, 1300)B[i] = C[1300-i]; for(int i = 1; i <= 2600; i++){ for(int j = 1; j <= 1300; j++){ if(i-j>=0)(A[i] += A[i-j] * C[j] % mod) %= mod; } } if(n <= 1300){ ll res = A[n]; for(int i = 1; i <= 1300; i++){ if(n - i < 0)continue; ll tmp = A[n-i] * CS[i+1] % mod; res = (res + tmp) % mod; } cout << res << endl; }else{ vector<ll> D = A; D.resize(1300); Kitamasa kt(D, B); vector<ll> co = kt.calc_coeff(n - 1299); ll res = 0; for(int i = n - 1299; i <= n; i++){ ll ai = 0; rep(j, 1300)ai = (ai + co[j] * A[j+i-n+1299] % mod) % mod; if(i < n){ res = (res + ai * CS[n-i+1] % mod) % mod; }else res = (res + ai) % mod; } cout << res << endl; } return 0; }