結果
| 問題 |
No.213 素数サイコロと合成数サイコロ (3-Easy)
|
| コンテスト | |
| ユーザー |
anta
|
| 提出日時 | 2015-11-14 18:15:02 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 5 ms / 3,000 ms |
| コード長 | 1,507 bytes |
| コンパイル時間 | 692 ms |
| コンパイル使用メモリ | 67,264 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-23 14:35:23 |
| 合計ジャッジ時間 | 1,068 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 2 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:68:18: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘ll’ {aka ‘long long int’} [-Wformat=]
68 | printf("%d\n", ans % Mod);
| ~^ ~~~~~~~~~
| | |
| int ll {aka long long int}
| %lld
ソースコード
#include <iostream>
#include <vector>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
using namespace std;
typedef long long ll;
typedef vector<int> Poly;
const int Mod = 1000000007;
inline void add(int &x, int y) { if((x += y) >= Mod) x -= Mod; }
Poly mul(const Poly &p, const Poly &q) {
int pn = p.size(), qn = q.size();
Poly r(pn + qn - 1);
rep(i, pn) rep(j, qn)
add(r[i + j], (ll)p[i] * q[j] % Mod);
return r;
}
Poly rem(const Poly &p, const Poly &q) {
int pd = p.size() - 1, qd = q.size() - 1;
if(pd < qd) return p;
Poly r = p;
for(int i = pd; i >= qd; -- i) {
int t = Mod - r[i];
rep(j, qd)
add(r[i - qd + j], (ll)t * q[j] % Mod);
}
r.resize(qd);
return r;
}
Poly doDP(vector<int> a, int n) {
vector<Poly> dp(n+1, Poly(a[5] * n + 1));
dp[0][0] = 1;
for(int d : a) {
rep(t, n) for(int i = t * a[0]; i <= t * d; ++ i)
add(dp[t + 1][i + d], dp[t][i]);
}
return dp[n];
}
int main() {
long long N; int P, C;
cin >> N >> P >> C;
vector<int> cntP, cntC;
cntP = doDP({ 2, 3, 5, 7, 11, 13 }, P);
cntC = doDP({ 4, 6, 8, 9, 10, 12 }, C);
int X = P * 13 + C * 12;
Poly pc = mul(cntP, cntC);
pc.resize(X + 1);
Poly mod(X + 1);
rep(i, X)
mod[i] = Mod - pc[X - i];
mod[X] = 1;
long long K = X + (N - 1);
Poly p = { 0, 1 };
int l = 0;
while((K >> l) > 1) ++ l;
Poly v = p;
for(-- l; l >= 0; -- l) {
v = rem(mul(v, v), mod);
if(K >> l & 1)
v = rem(mul(v, p), mod);
}
ll ans = 0;
rep(i, v.size()) ans += v[i];
printf("%d\n", ans % Mod);
return 0;
}
anta