Submission #97982
Source Code Expand
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <assert.h>
#include <sys/time.h>
#include <fstream>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define REP(i,n) FOR(i,0,n)
#define each(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define deb(x) cerr << #x << " = " << (x) << " , ";
#define debl cerr << " (L" << __LINE__ << ")"<< endl;
#define sz(s) (int)((s).size())
#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizeof(a))
#define pb push_back
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define MP(x,y) make_pair((x),(y))
double pi=3.14159265358979323846;
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
template<typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& z){
os << "[ ";
REP(i,z.size())os << z[i] << ", " ;
return ( os << "]" << endl);
}
template<typename T> std::ostream& operator<<(std::ostream& os, const set<T>& z){
os << "set( ";
EACH(p,z)os << (*p) << ", " ;
return ( os << ")" << endl);
}
template<typename T,typename U> std::ostream& operator<<(std::ostream& os, const map<T,U>& z){
os << "{ ";
EACH(p,z)os << (p->first) << ": " << (p->second) << ", " ;
return ( os << "}" << endl);
}
template<typename T,typename U> std::ostream& operator<<(std::ostream& os, const pair<T,U>& z){
return ( os << "(" << z.first << ", " << z.second << ",)" );
}
double get_time(){
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec + tv.tv_usec*1e-6;
}
typedef unsigned int uint32_t;
struct RND{
uint32_t x;
uint32_t y;
uint32_t z;
uint32_t w;
RND(){
x=123456789;
y=362436069;
z=521288629;
w=88675123;
}
void init(int seed){
x=123456789;
y=362436069;
z=521288629;
w=seed+100;
REP(i,10)get();
}
uint32_t get(){
uint32_t t;
t=x^(x<<11);
x=y;y=z;z=w;
w=(w^(w>>19))^(t^(t>>8));
return w;
}
};
RND rnd;
ll mod=1000000007;
struct mint{
ll value;
mint():value(0){}
mint(ll v):value((v%mod+mod)%mod){}
};
mint& operator+=(mint&a, mint b){return a=a.value+b.value;}
mint& operator-=(mint&a, mint b){return a=a.value-b.value;}
mint& operator*=(mint&a, mint b){return a=a.value*b.value;}
mint operator+(mint a, mint b){return a+=b;}
mint operator-(mint a, mint b){return a-=b;}
mint operator*(mint a, mint b){return a*=b;}
mint operator-(mint a){return 0-a;}
bool operator==(mint a, mint b){return a.value==b.value;}
bool operator!=(mint a, mint b){return a.value!=b.value;}
std::ostream& operator<<(std::ostream& os, const mint& m){
return ( os << m.value );}
ll extgcd(ll a, ll b, ll &x, ll &y){
ll d=a;
if(b!=0){
d=extgcd(b, a%b, y, x);
y-=(a/b)*x;
}
else{
x=1,y=0;
}
return d;
}
ll modinverse(ll a, ll b){
ll x,y;
ll d=extgcd(a,b, x, y);
assert(d==1);
return (x%b+b)%b;
}
mint& operator/=(mint&a, mint b){return a=a.value*modinverse(b.value,mod);}
mint operator/(mint a, mint b){return a/=b;}
typedef vector<mint> vm;
ll K,N;
vm sq(vm _z){
vl z(K);
rep(j,z.size()) z[j] = _z[j].value;
vl a(2*K);
rep(j1,z.size()) rep(j2,z.size()){
a[j1+j2] += (z[j1] * z[j2])%mod;
}
rep(j,2*K) a[j]%=mod;
for(int j=2*K-2; j>=K; j--){
ll v = a[j];
rep(j2,K) a[j-j2-1] = (a[j-j2-1]+v)%mod;
}
rep(j,K) a[j]%=mod;
vm ret(K);
rep(j,K) ret[j] = a[j];
return ret;
}
vm p1(vm z){
vm ret(K);
rep(j,K-1) ret[j+1] = z[j];
rep(j,K) ret[j] += z[K-1];
return ret;
}
vm cal(ll N){
if(N==0){
vm ret(K);
ret[0] = 1;
return ret;
}
if(N%2==0)return sq(cal(N/2));
else return p1(cal(N-1));
}
void _main(istream &inp){
inp >> K >> N;
double start = get_time();
vm u = cal(N-1);
{
mint ans = 0;
rep(j,K) ans += u[j];
cout << ans << endl;
}
}
int main(){
if(0){
ifstream ifs("test.txt");
_main(ifs);
}
else{
_main(cin);
}
return 0;
}
Submission Info
Submission Time |
|
Task |
T - フィボナッチ |
User |
hirosegolf |
Language |
C++11 (GCC 4.8.1) |
Score |
8 |
Code Size |
4701 Byte |
Status |
AC |
Exec Time |
892 ms |
Memory |
788 KB |
Judge Result
Set Name |
All |
Score / Max Score |
8 / 8 |
Status |
|
Set Name |
Test Cases |
All |
00, 01, 02, 03, 04, 90, 91 |
Case Name |
Status |
Exec Time |
Memory |
00 |
AC |
892 ms |
784 KB |
01 |
AC |
506 ms |
780 KB |
02 |
AC |
888 ms |
784 KB |
03 |
AC |
156 ms |
784 KB |
04 |
AC |
256 ms |
784 KB |
90 |
AC |
20 ms |
784 KB |
91 |
AC |
20 ms |
788 KB |