結果

問題 No.1269 I hate Fibonacci Number
ユーザー furafura
提出日時 2020-10-23 23:30:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,382 bytes
コンパイル時間 2,607 ms
コンパイル使用メモリ 219,192 KB
実行使用メモリ 130,008 KB
最終ジャッジ日時 2023-09-28 18:45:46
合計ジャッジ時間 8,065 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 129 ms
7,036 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 64 ms
9,204 KB
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

class mint{
	static const int MOD=1e9+7;
	int x;
public:
	mint():x(0){}
	mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }

	mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
	mint& operator-=(const mint& m){ x-=m.x; if(x<   0) x+=MOD; return *this; }
	mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
	mint& operator/=(const mint& m){ return *this*=inverse(m); }
	mint operator+(const mint& m)const{ return mint(*this)+=m; }
	mint operator-(const mint& m)const{ return mint(*this)-=m; }
	mint operator*(const mint& m)const{ return mint(*this)*=m; }
	mint operator/(const mint& m)const{ return mint(*this)/=m; }
	mint operator-()const{ return -x; }

	friend mint inverse(const mint& m){
		int a=m.x,b=MOD,u=1,v=0;
		while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
		return u;
	}

	friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=t; return is; }
	friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
	int to_int()const{ return x; }
};

mint operator+(long long x,const mint& m){ return mint(x)+m; }
mint operator-(long long x,const mint& m){ return mint(x)-m; }
mint operator*(long long x,const mint& m){ return mint(x)*m; }
mint operator/(long long x,const mint& m){ return mint(x)/m; }

int n;
vector<string> F;

map<vector<pair<int,int>>,mint> memo[5000];

mint dfs(int i,vector<pair<int,int>> match){
	if(i==n){
		return 1;
	}

	if(memo[i].count(match)>0) return memo[i][match];

	mint& res=memo[i][match];
	for(char d='0';d<='9';d++){
		vector<pair<int,int>> match2;
		bool ng=false;
		for(auto [id,len]:match){
			if(F[id][len]==d){
				if(F[id].length()==len+1){
					ng=true;
					break;
				}
				match2.emplace_back(id,len+1);
			}
		}
		if(ng) continue;

		rep(id,F.size()){
			if(F[id][0]==d){
				if(F[id].length()==1){
					ng=true;
					break;
				}
				match2.emplace_back(id,1);
			}
		}
		if(ng) continue;

		sort(match2.begin(),match2.end());
		res+=dfs(i+1,match2);
	}
	return res;
}

int main(){
	lint l,r; scanf("%d%lld%lld",&n,&l,&r);

	lint fib[90]={1,1};
	for(int i=2;i<90;i++){
		fib[i]=fib[i-1]+fib[i-2];
	}
	for(int i=1;i<90;i++){
		if(l<=fib[i] && fib[i]<=r){
			F.emplace_back(to_string(fib[i]));
		}
	}

	cout<<dfs(0,{})-1<<'\n';

	return 0;
}
0