結果
問題 | No.1269 I hate Fibonacci Number |
ユーザー | mtsd |
提出日時 | 2020-10-23 23:48:09 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 173 ms / 3,000 ms |
コード長 | 2,981 bytes |
コンパイル時間 | 1,714 ms |
コンパイル使用メモリ | 142,992 KB |
実行使用メモリ | 42,648 KB |
最終ジャッジ日時 | 2023-09-28 19:07:50 |
合計ジャッジ時間 | 4,365 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,380 KB |
testcase_02 | AC | 6 ms
4,376 KB |
testcase_03 | AC | 2 ms
4,380 KB |
testcase_04 | AC | 2 ms
4,376 KB |
testcase_05 | AC | 2 ms
4,380 KB |
testcase_06 | AC | 2 ms
4,380 KB |
testcase_07 | AC | 2 ms
4,380 KB |
testcase_08 | AC | 2 ms
4,380 KB |
testcase_09 | AC | 2 ms
4,376 KB |
testcase_10 | AC | 2 ms
4,380 KB |
testcase_11 | AC | 2 ms
4,376 KB |
testcase_12 | AC | 2 ms
4,380 KB |
testcase_13 | AC | 61 ms
26,608 KB |
testcase_14 | AC | 85 ms
32,868 KB |
testcase_15 | AC | 18 ms
13,812 KB |
testcase_16 | AC | 62 ms
20,976 KB |
testcase_17 | AC | 4 ms
4,380 KB |
testcase_18 | AC | 68 ms
24,228 KB |
testcase_19 | AC | 58 ms
26,920 KB |
testcase_20 | AC | 18 ms
10,388 KB |
testcase_21 | AC | 44 ms
17,116 KB |
testcase_22 | AC | 41 ms
18,736 KB |
testcase_23 | AC | 48 ms
22,908 KB |
testcase_24 | AC | 20 ms
9,104 KB |
testcase_25 | AC | 31 ms
16,752 KB |
testcase_26 | AC | 6 ms
5,272 KB |
testcase_27 | AC | 10 ms
10,824 KB |
testcase_28 | AC | 13 ms
6,388 KB |
testcase_29 | AC | 40 ms
25,836 KB |
testcase_30 | AC | 23 ms
18,340 KB |
testcase_31 | AC | 97 ms
28,688 KB |
testcase_32 | AC | 27 ms
11,544 KB |
testcase_33 | AC | 173 ms
42,648 KB |
testcase_34 | AC | 22 ms
23,348 KB |
testcase_35 | AC | 27 ms
24,156 KB |
testcase_36 | AC | 10 ms
4,376 KB |
testcase_37 | AC | 1 ms
4,380 KB |
testcase_38 | AC | 10 ms
4,376 KB |
ソースコード
#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; }