結果
問題 | No.213 素数サイコロと合成数サイコロ (3-Easy) |
ユーザー |
![]() |
提出日時 | 2015-05-22 22:58:54 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 736 ms / 3,000 ms |
コード長 | 3,231 bytes |
コンパイル時間 | 760 ms |
コンパイル使用メモリ | 87,264 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-06 05:23:48 |
合計ジャッジ時間 | 3,091 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 2 |
ソースコード
#include <cstdio>#include <algorithm>#include <stack>#include <queue>#include <deque>#include <vector>#include <string>#include <string.h>#include <cstdlib>#include <ctime>#include <cmath>#include <map>#include <set>#include <iostream>#include <sstream>#include <numeric>#include <cctype>#define fi first#define se second#define rep(i,n) for(int i = 0; i < n; ++i)#define rrep(i,n) for(int i = 1; i <= n; ++i)#define drep(i,n) for(int i = n-1; i >= 0; --i)#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)#define rng(a) a.begin(),a.end()#define maxs(x,y) x = max(x,y)#define mins(x,y) x = min(x,y)#define pb push_back#define sz(x) (int)(x).size()#define pcnt __builtin_popcount#define snuke srand((unsigned)clock()+(unsigned)time(NULL));using namespace std;typedef long long int ll;typedef pair<int,int> P;typedef vector<int> vi;typedef vector<vi> vvi;inline int in() { int x; scanf("%d",&x); return x;}inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}const int MX = 155, MN = 12, INF = 1000010000;const ll LINF = 1000000000000000000ll;const double eps = 1e-10;const int a[2][6] = {{2,3,5,7,11,13},{4,6,8,9,10,12}};ll n, p, c;// Mod intconst int mod = 1000000007;struct mint{ll x;mint():x(0){}mint(ll x):x((x%mod+mod)%mod){}mint operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}mint operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}mint operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}mint operator+(const mint& a)const{ return mint(*this) += a;}mint operator-(const mint& a)const{ return mint(*this) -= a;}mint operator*(const mint& a)const{ return mint(*this) *= a;}bool operator==(const mint& a)const{ return x == a.x;}};//// Matrixstruct mat{typedef mint TT;int h, w;vector<vector<TT> > d;mat(){}mat(int h, int w, TT v=0):h(h),w(w),d(h,vector<TT>(w,v)){}void fil(TT v=0){ rep(i,h)rep(j,w) d[i][j] = v;}void uni(){ rep(i,h)rep(j,w) d[i][j] = (i==j);}mat operator*(const mat& a)const{ // w = a.hmat res(h,a.w);rep(i,h)rep(k,w)rep(j,a.w) res.d[i][j] += d[i][k]*a.d[k][j];return res;}mat power(ll a){ // h = wif(a == 0){mat res(h,w); res.uni();return res;}mat res = power(a/2);res = res*res;if(a&1) res = res*(*this);return res;}};//mint dp[MX];mint d[MN][MX];int main(){vi p(2);cin >> n >> p[0] >> p[1];d[0][0] = 1;rep(i,6) {rep(j,p[0])for (int k = a[0][i]; k < MX-2; ++k) {d[j+1][k] += d[j][k-a[0][i]];}}rep(i,MX) d[0][i] = d[p[0]][i];rrep(i,MN-1)rep(j,MX) d[i][j] = 0;rep(i,6) {rep(j,p[1])for (int k = a[1][i]; k < MX-2; ++k) {d[j+1][k] += d[j][k-a[1][i]];}}rep(i,MX) dp[i] = d[p[1]][i];int s = MX-5;mat x(s,s), y(s,1);rep(i,s-1) x.d[i+1][i] = 1;rep(i,s) x.d[0][i] = dp[i+1];y.d[0][0] = 1;x = x.power(n-1);y = x*y;mint ans = 0, sum = 0;rep(i,s) {sum += dp[s-i];ans += y.d[s-i-1][0]*sum;// cout<<i<<" "<<y.d[i][0].x<<endl;}cout<<ans.x<<endl;return 0;}