結果

問題 No.1269 I hate Fibonacci Number
ユーザー kotatsugamekotatsugame
提出日時 2020-10-24 02:23:06
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 282 ms / 3,000 ms
コード長 3,822 bytes
コンパイル時間 1,408 ms
コンパイル使用メモリ 104,820 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-28 20:00:27
合計ジャッジ時間 4,893 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 12 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 6 ms
4,380 KB
testcase_14 AC 237 ms
4,380 KB
testcase_15 AC 16 ms
4,376 KB
testcase_16 AC 266 ms
4,376 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 282 ms
4,376 KB
testcase_19 AC 117 ms
4,380 KB
testcase_20 AC 27 ms
4,380 KB
testcase_21 AC 158 ms
4,504 KB
testcase_22 AC 104 ms
4,380 KB
testcase_23 AC 103 ms
4,376 KB
testcase_24 AC 73 ms
4,380 KB
testcase_25 AC 56 ms
4,376 KB
testcase_26 AC 5 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 6 ms
4,376 KB
testcase_29 AC 41 ms
4,376 KB
testcase_30 AC 13 ms
4,376 KB
testcase_31 AC 190 ms
4,380 KB
testcase_32 AC 94 ms
4,380 KB
testcase_33 AC 10 ms
4,376 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 10 ms
4,376 KB
testcase_36 AC 3 ms
4,376 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 7 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
a.cpp:14:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]

ソースコード

diff #

#line 1 "a.cpp"
#include<iostream>
#include<vector>
#include<map>
#include<queue>
using namespace std;
#line 3 "/home/kotatsugame/library/math/modint.cpp"
#include<utility>
template<int m>
struct modint{
	unsigned int x;
	constexpr modint()noexcept:x(){}
	template<typename T>
	constexpr modint(T x_)noexcept:x((x_%=m)<0?x_+m:x_){}
	constexpr unsigned int val()const noexcept{return x;}
	constexpr modint&operator++()noexcept{if(++x==m)x=0;return*this;}
	constexpr modint&operator--()noexcept{if(x==0)x=m;--x;return*this;}
	constexpr modint operator++(int)noexcept{modint res=*this;++*this;return res;}
	constexpr modint operator--(int)noexcept{modint res=*this;--*this;return res;}
	constexpr modint&operator+=(const modint&a)noexcept{x+=a.x;if(x>=m)x-=m;return*this;}
	constexpr modint&operator-=(const modint&a)noexcept{if(x<a.x)x+=m;x-=a.x;return*this;}
	constexpr modint&operator*=(const modint&a)noexcept{x=(unsigned long long)x*a.x%m;return*this;}
	constexpr modint&operator/=(const modint&a)noexcept{return*this*=a.inv();}
	constexpr modint operator+()const noexcept{return*this;}
	constexpr modint operator-()const noexcept{return modint()-*this;}
	constexpr modint pow(long long n)const noexcept
	{
		if(n<0)return pow(-n).inv();
		modint x=*this,r=1;
		for(;n;x*=x,n>>=1)if(n&1)r*=x;
		return r;
	}
	constexpr modint inv()const noexcept
	{
		int s=x,t=m,x=1,u=0;
		while(t)
		{
			int k=s/t;
			s-=k*t;
			swap(s,t);
			x-=k*u;
			swap(x,u);
		}
		return modint(x);
	}
	friend constexpr modint operator+(const modint&a,const modint&b){return modint(a)+=b;}
	friend constexpr modint operator-(const modint&a,const modint&b){return modint(a)-=b;}
	friend constexpr modint operator*(const modint&a,const modint&b){return modint(a)*=b;}
	friend constexpr modint operator/(const modint&a,const modint&b){return modint(a)/=b;}
	friend constexpr bool operator==(const modint&a,const modint&b){return a.x==b.x;}
	friend constexpr bool operator!=(const modint&a,const modint&b){return a.x!=b.x;}
	friend ostream&operator<<(ostream&os,const modint&a){return os<<a.x;}
	friend istream&operator>>(istream&is,modint&a){long long v;is>>v;a=modint(v);return is;}
};
#line 7 "a.cpp"
using mint=modint<(int)1e9+7>;
int N;
long L,R;
int succ[99][20][10];
int sz[99];
map<vector<int>,int>mp;
vector<vector<int> >to;
main()
{
	cin>>N>>L>>R;
	int cnt=0;
	{
		long a=1,b=1;
		for(;a<=R;)
		{
			if(L<=a)
			{
				string s=to_string(a);
				for(int i=0;i<s.size();i++)
				{
					for(int j=0;j<=9;j++)
					{
						string t=s.substr(0,i);
						t+=j+'0';
						while(true)
						{
							bool now=true;
							for(int I=0;I<t.size();I++)
							{
								if(s[I]!=t[I])
								{
									now=false;
									break;
								}
							}
							if(now)break;
							t=t.substr(1);
						}
						succ[cnt][i][j]=t.size();
					}
				}
				sz[cnt]=s.size();
				cnt++;
			}
			{
				long c=a+b;
				b=a;
				a=c;
			}
		}
	}
	vector<int>fst(cnt,0);
	{
		int mps=0;
		queue<vector<int> >P;
		P.push(fst);
		mp[fst]=mps++;
		to.push_back(vector<int>(10));
		while(!P.empty())
		{
			vector<int>now=P.front();P.pop();
			int id=mp[now];
			for(int c=0;c<=9;c++)
			{
				vector<int>nxt(cnt);
				bool out=false;
				for(int i=0;i<cnt;i++)
				{
					nxt[i]=succ[i][now[i]][c];
					if(nxt[i]==sz[i])
					{
						out=true;
					}
				}
				if(mp.find(nxt)==mp.end())
				{
					if(out)mp[nxt]=-1;
					else
					{
						to.push_back(vector<int>(10));
						mp[nxt]=mps++;
						P.push(nxt);
					}
				}
				to[id][c]=mp[nxt];
			}
		}
	}
	map<int,mint>now;
	now[mp[fst]]=1;
	for(;N--;)
	{
		map<int,mint>nxt;
		for(pair<int,mint>p:now)
		{
			for(int c=0;c<=9;c++)
			{
				if(to[p.first][c]>=0)
				{
					nxt[to[p.first][c]]+=p.second;
				}
			}
		}
		now=nxt;
	}
	mint ans=-1;
	for(pair<int,mint>p:now)ans+=p.second;
	cout<<ans<<endl;
}
0