Submission #342773


Source Code Expand

#include<iostream>
#include<algorithm>
using namespace std;
#define rep(i,a,b) for(auto (i)=(a);(i)<(b);(i)++)
#define rev(i,a,b) for(auto (i)=(b)-1;(i)>=(a);(i)--)
#define MOD 1000000007ll
#define LL long long
LL M;

LL a[33][2 * 1000 - 1] = { 0, 1 };
LL a0[1000];

//a(0)からa(2*m-2)の形のa(n)をa(0)からa(m-1)の形に直す
void form(LL* n){
	rev(i, M, 2 * M - 1){
		rep(j, 1, M + 1)
			n[i - j] = (n[i - j] + n[i]) % MOD;
		n[i] = 0;
	}
}

void print(LL *result){
	rep(j, 0, 3){
		printf("%d ", result[j]);
	}
	cout << endl;
}

void add(LL *l, LL *r, LL *ans){
	//print(l); print(r);
	rep(i, 0, 2 * M - 1){
		ans[i] = 0;
	}
	rep(i, 0, M)
		rep(j, 0, M){
			ans[i + j] = (ans[i + j] + (l[i] * r[j]) % MOD) % MOD;
		}
	form(ans);

	//print(ans);
}


//a(2^n)を求める
void init(){
	//初期化
	rep(i, 0, M){
		a0[i] = 1;
	}
	rep(n, 0, 32){

		//a(2^n)の計算
		add(a[n], a[n], a[n + 1]);
	}
}



LL calc(int n){
	LL result[2000] = { 1 };
	LL tmp[2000] = { 1 };
	rep(i, 0, 32){
		if (1 & n){
			add(tmp, a[i], result);
			rep(j, 0, M)tmp[j] = result[j];
		}
		n >>= 1;
	}
	LL ans = 0;
	rep(i, 0, M)
		ans =(ans+ (result[i]*a0[i])%MOD)%MOD;
	return(ans);
}


int main(void){
	int n;
	cin >> M >> n;
	init();
	cout << calc(n - 1) << endl;
}

Submission Info

Submission Time
Task T - フィボナッチ
User btk15049
Language C++11 (GCC 4.8.1)
Score 8
Code Size 1333 Byte
Status AC
Exec Time 663 ms
Memory 1564 KB

Judge Result

Set Name All
Score / Max Score 8 / 8
Status
AC × 7
Set Name Test Cases
All 00, 01, 02, 03, 04, 90, 91
Case Name Status Exec Time Memory
00 AC 663 ms 1496 KB
01 AC 377 ms 1460 KB
02 AC 602 ms 1468 KB
03 AC 123 ms 1336 KB
04 AC 491 ms 1564 KB
90 AC 28 ms 1076 KB
91 AC 26 ms 1176 KB