結果
| 問題 |
No.214 素数サイコロと合成数サイコロ (3-Medium)
|
| コンテスト | |
| ユーザー |
kmjp
|
| 提出日時 | 2015-05-26 08:28:12 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 2,170 bytes |
| コンパイル時間 | 1,592 ms |
| コンパイル使用メモリ | 165,920 KB |
| 実行使用メモリ | 6,940 KB |
| 最終ジャッジ日時 | 2024-07-06 08:37:37 |
| 合計ジャッジ時間 | 13,985 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 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,M;
int AA[6]={2,3,5,7,11,13};
int B[6]={4,6,8,9,10,12};
ll mo=1000000007;
ll dp[2][400][4000];
ll dp2[8000];
ll single[8010];
vector<ll> mult(vector<ll>& v,vector<ll>& v2) {
int i,j;
int M=v.size();
vector<ll> t(2*M,0);
FOR(i,M) FOR(j,M) t[i+j] += v[i]*v2[j] % mo;
for(i=2*M-1;i>=M;i--) {
ll ti=t[i]%mo;
if(ti) for(j=1;j<=M;j++) t[i-j] += single[j]*ti % mo;
}
FOR(j,M) ((t[j]%=mo)+=mo)%=mo;
t.resize(M);
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,y*13+1) 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,y*12+1) 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,700) FOR(y,700) (single[x+y] += dp[0][P][x]*dp[1][C][y])%=mo;
M=P*13+C*12;
dp2[0]=1;
for(i=1;i<=2*M+2;i++) {
FOR(x,M+1) if(i>=x) dp2[i] += dp2[i-x]*single[x]%mo;
dp2[i] %= mo;
}
ll tot=0;
if(N<=2*M) {
for(ll v=max(0LL,N-M);v<N;v++) {
for(x=1;x<=M;x++) if(v+x>=N) tot += dp2[v]*single[x]%mo;
tot %= mo;
}
}
else {
ll vv=N-M;
vector<ll> R(M,0),V(M,0);
R[0]=V[1]=1;
while(vv) {
if(vv%2) R=mult(R,V);
V=mult(V,V);
vv/=2;
}
for(ll v=max(0LL,N-M);v<N;v++) {
ll pat=0;
for(x=0;x<=M-1;x++) pat += R[x]*dp2[v-(N-M)+x] % mo;
pat %= mo;
for(x=1;x<=M;x++) if(v+x>=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