結果
| 問題 |
No.214 素数サイコロと合成数サイコロ (3-Medium)
|
| コンテスト | |
| ユーザー |
kmjp
|
| 提出日時 | 2015-05-23 00:17:08 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,160 bytes |
| コンパイル時間 | 1,321 ms |
| コンパイル使用メモリ | 167,092 KB |
| 実行使用メモリ | 63,476 KB |
| 最終ジャッジ日時 | 2024-07-06 05:46:17 |
| 合計ジャッジ時間 | 13,547 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 2 TLE * 1 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<to;x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------
ll N;
int P,C,K;
int AA[6]={2,3,5,7,11,13};
int B[6]={4,6,8,9,10,12};
ll mo=1000000007;
ll dp[2][60][1000];
ll dp2[4010];
ll single[4010];
ll A[3000][3000];
vector<ll> mult(vector<ll>& v,vector<ll>& v2) {
int i,j;
vector<ll> t(2*K,0);
FOR(i,K) FOR(j,K) t[i+j] += v[i]*v2[j]%mo;
for(i=K;i<2*K-1;i++) {
ll ti=t[i]%mo;
FOR(j,K) t[j] += A[i][j]*ti % mo;
}
FOR(j,K) ((t[j]%=mo)+=mo)%=mo;
t.resize(K);
return t;
}
void solve() {
int i,j,k,l,r,x,y; string s;
cin>>N>>P>>C;
dp[0][0][0]=dp[1][0][0]=1;
FOR(x,6) {
for(y=P-1;y>=0;y--) {
FOR(i,700) if(dp[0][y][i]) {
for(r=1;r+y<=P;r++) (dp[0][y+r][i+r*AA[x]] += dp[0][y][i])%=mo;
}
}
for(y=C-1;y>=0;y--) {
FOR(i,700) if(dp[1][y][i]) {
for(r=1;r+y<=C;r++) (dp[1][y+r][i+r*B[x]] += dp[1][y][i])%=mo;
}
}
}
FOR(x,900) FOR(y,900) (single[x+y] += dp[0][P][x]*dp[1][C][y])%=mo;
int M=P*13+C*12;
K=M+1;
dp2[0]=1;
for(i=1;i<=3000;i++) {
FOR(x,M+1) if(i>=x) dp2[i] += dp2[i-x]*single[x]%mo;
dp2[i] %= mo;
}
ll tot=0;
if(N<=3000) {
FOR(i,N) {
FOR(x,M+1) if(i+x>=N) tot += dp2[i] * single[x] % mo;
}
}
else {
FOR(i,K) A[i][i]=1;
for(x=K;x<2*K;x++) {
FOR(y,K) A[x][y]=dp2[x-y];
}
ll v=N-2*M;
vector<ll> R(K,0),V(K,0);
R[0]=V[1]=1;
while(v) {
if(v%2) R=mult(R,V);
V=mult(V,V);
v/=2;
}
v=N-M;
FOR(y,M) {
ll pat=0;
FOR(x,M+1) pat += R[x] * dp2[x+y] % mo;
pat %= mo;
FOR(x,M+1) if(v+x+y>=N) tot += pat*single[x]%mo;
tot %= mo;
}
}
cout<<tot%mo<<endl;
}
int main(int argc,char** argv){
string s;int i;
if(argc==1) ios::sync_with_stdio(false);
FOR(i,argc-1) s+=argv[i+1],s+='\n';
FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
solve(); return 0;
}
kmjp