結果
| 問題 |
No.1269 I hate Fibonacci Number
|
| コンテスト | |
| ユーザー |
mtsd
|
| 提出日時 | 2020-10-23 23:48:09 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 182 ms / 3,000 ms |
| コード長 | 2,981 bytes |
| コンパイル時間 | 1,828 ms |
| コンパイル使用メモリ | 142,928 KB |
| 実行使用メモリ | 42,752 KB |
| 最終ジャッジ日時 | 2024-07-21 13:49:47 |
| 合計ジャッジ時間 | 4,090 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 36 |
ソースコード
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
std::fill( (T*)array, (T*)(array+N), val );
}
template<class T> inline bool chmax(T &a, T b){
if(a<b){
a = b;
return true;
}
return false;
}
template<class T> inline bool chmin(T &a, T b){
if(a>b){
a = b;
return true;
}
return false;
}
ll p[300];
ll dp[5001][1000];
int main(){
int n;
cin >> n;
ll L,R;
cin >> L >> R;
p[0] = 1;
p[1] = 1;
vector<string>a;
for(int i=1;i<300;i++){
if(L<=p[i]&&p[i]<=R)a.push_back(to_string(p[i]));
if(p[i]>R)break;
p[i+1] = p[i] + p[i-1];
}
set<string> st;
set<string> pp;
rep(i,a.size()){
string tmp;
for(int j=0;j<a[i].size();j++){
tmp.push_back(a[i][j]);
st.insert(tmp);
}
pp.insert(a[i]);
}
map<string,int> mp;
int id = 1;
vector<string> s;
s.push_back("");
for(auto x:st){
// cerr << x << endl;
mp[x] = id;
s.push_back(x);
id++;
}
vector<vector<int> >g(id);
vector<bool>flag(id);
rep(i,id){
string t = s[i];
int len = t.size();
rep(a,len+1){
rep(j,a){
string q = t.substr(j,a-j+1);
if(pp.count(q)){
flag[mp[t]] = 1;
// cerr << "ng: " << q << endl;
}
}
}
}
rep(i,id){
rep(j,10){
string t = s[i];
t.push_back('0'+j);
int len = t.size();
int nxt = 0;
rep(k,len){
if(st.count(t.substr(k,len-k))){
nxt = mp[t.substr(k,len-k)];
break;
}
}
// cerr << s[i] << " " << t << " " << s[nxt] << endl;
g[i].push_back(nxt);
}
}
dp[0][0] = 1;
rep(i,n){
rep(j,id){
for(auto x:g[j]){
if(flag[x])continue;
dp[i+1][x] += dp[i][j];
dp[i+1][x] %= MOD;
}
}
}
ll res = 0;
rep(i,id){
res += dp[n][i];
res %= MOD;
}
cout << (res+MOD-1)%MOD << endl;
return 0;
}
mtsd