結果

問題 No.1269 I hate Fibonacci Number
ユーザー SSRSSSRS
提出日時 2020-10-23 22:56:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 135 ms / 3,000 ms
コード長 1,890 bytes
コンパイル時間 2,495 ms
コンパイル使用メモリ 198,080 KB
実行使用メモリ 31,068 KB
最終ジャッジ日時 2023-09-28 17:26:44
合計ジャッジ時間 4,914 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 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,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 40 ms
11,408 KB
testcase_14 AC 56 ms
13,640 KB
testcase_15 AC 9 ms
4,820 KB
testcase_16 AC 45 ms
11,040 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 47 ms
11,880 KB
testcase_19 AC 33 ms
9,444 KB
testcase_20 AC 10 ms
4,820 KB
testcase_21 AC 29 ms
8,592 KB
testcase_22 AC 26 ms
7,828 KB
testcase_23 AC 27 ms
8,332 KB
testcase_24 AC 15 ms
5,556 KB
testcase_25 AC 18 ms
6,376 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 10 ms
4,576 KB
testcase_29 AC 17 ms
6,296 KB
testcase_30 AC 8 ms
4,532 KB
testcase_31 AC 70 ms
15,976 KB
testcase_32 AC 19 ms
6,348 KB
testcase_33 AC 135 ms
31,068 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 8 ms
4,380 KB
testcase_36 AC 9 ms
4,376 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 11 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int main(){
  int N;
  cin >> N;
  long long L, R;
  cin >> L >> R;
  vector<long long> F(2, 1);
  while (1){
    long long next = F[F.size() - 2] + F[F.size() - 1];
    if (next <= R){
      F.push_back(next);
    } else {
      break;
    }
  }
  set<string> ng;
  for (long long x : F){
    if (L <= x && x <= R){
      ng.insert(to_string(x));
    }
  }
  vector<string> prf;
  prf.push_back("");
  for (string S : ng){
    int len = S.size();
    for (int j = 0; j <= len; j++){
      prf.push_back(S.substr(0, j));
    }
  }
  sort(prf.begin(), prf.end());
  prf.erase(unique(prf.begin(), prf.end()), prf.end());
  int V = prf.size();
  map<string, int> id;
  for (int i = 0; i < V; i++){
    id[prf[i]] = i;
  }
  vector<vector<int>> next(V, vector<int>(10, -1));
  for (int i = 0; i < V; i++){
    for (int j = 0; j <= 9; j++){
      string S = prf[i];
      S += '0' + j;
      int len = S.size();
      bool ok = true;
      for (int k = 0; k <= len; k++){
        string T = S.substr(k);
        if (ng.count(T)){
          ok = false;
        }
      }
      if (ok){
        for (int k = 0; k <= len; k++){
          string T = S.substr(k);
          if (id.count(T)){
            next[i][j] = id[T];
            break;
          }
        }
      }
    }
  }
  vector<vector<long long>> dp(N + 1, vector<long long>(V, 0));
  dp[0][0] = 1;
  for (int i = 0; i < N; i++){
    for (int j = 0; j < V; j++){
      for (int k = 0; k <= 9; k++){
        if (next[j][k] != -1){
          if (!(i == 0 && k == 0)){
            dp[i + 1][next[j][k]] += dp[i][j];
            dp[i + 1][next[j][k]] %= MOD;
          }
        }
      }
    }
  }
  long long ans = 0;
  for (int i = 1; i <= N; i++){
    for (int j = 0; j < V; j++){
      ans += dp[i][j];
      ans %= MOD;
    }
  }
  cout << ans << endl;
}
0