結果
問題 | No.213 素数サイコロと合成数サイコロ (3-Easy) |
ユーザー |
![]() |
提出日時 | 2015-05-22 23:30:44 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 1,762 ms / 3,000 ms |
コード長 | 2,260 bytes |
コンパイル時間 | 1,458 ms |
コンパイル使用メモリ | 162,168 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-06 05:37:16 |
合計ジャッジ時間 | 5,032 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 2 |
コンパイルメッセージ
main.cpp: In function ‘ll getpat(ll)’: main.cpp:49:1: warning: no return statement in function returning non-void [-Wreturn-type] 49 | } | ^
ソースコード
#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;int A[6]={2,3,5,7,11,13};int B[6]={4,6,8,9,10,12};ll mo=1000000007;ll dp[2][7][1000];ll dp2[1010];ll single[1010];const int MAT=130;struct Mat { ll v[MAT][MAT]; };Mat mulmat(Mat& a,Mat& b,int n=MAT) {int x,y,z; Mat r;FOR(x,n) FOR(y,n) r.v[x][y]=0;FOR(x,n) FOR(z,n) FOR(y,n) r.v[x][y] += (a.v[x][z]*b.v[z][y]) % mo;FOR(x,n) FOR(y,n) r.v[x][y]%=mo;return r;}Mat powmat(ll p,Mat a,int n=MAT) {int i,x,y; Mat r;FOR(x,n) FOR(y,n) r.v[x][y]=0;FOR(i,n) r.v[i][i]=1;while(p) {if(p%2) r=mulmat(r,a,n);a=mulmat(a,a,n);p>>=1;}return r;}ll getpat(ll v) {}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,90) if(dp[0][y][i]) {for(r=1;r+y<=P;r++) (dp[0][y+r][i+r*A[x]] += dp[0][y][i])%=mo;}}for(y=C-1;y>=0;y--) {FOR(i,90) 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,90) FOR(y,90) single[x+y] += dp[0][P][x]*dp[1][C][y];int M=P*13+C*12;dp2[0]=1;for(i=1;i<=1000;i++) {FOR(x,M+1) if(i>=x) dp2[i] += dp2[i-x]*single[x]%mo;dp2[i] %= mo;}ll tot=0;if(N<=1000) {FOR(i,N) {FOR(x,M+1) if(i+x>=N) tot += dp2[i] * single[x] % mo;}}else {Mat mm;ZERO(mm.v);FOR(i,M) mm.v[i][i+1]=1;for(i=1;i<=M;i++) mm.v[M][M+1-i]=single[i];ll v=N-(M+1);Mat m2=powmat(v,mm,M+1);FOR(i,M+1) {ll pat=0;FOR(x,M+1) pat += m2.v[i][x] * dp2[x] % mo;pat %= mo;FOR(x,M+1) if(v+i+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;}