結果

問題 No.645 Count Permutation
ユーザー 193s
提出日時 2018-02-03 12:24:37
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 1,212 bytes
コンパイル時間 895 ms
コンパイル使用メモリ 93,952 KB
実行使用メモリ 26,752 KB
最終ジャッジ日時 2024-06-11 15:20:00
合計ジャッジ時間 2,441 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
inline void add(int &x, int v) { x += v; if (x >= MOD) x -= MOD; }

int N;
long long L, R;
int dp[100001][60];
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> L >> R;
  dp[N-1][0] = 1;
  for (int x=N-1; x>=1; x--) {
    rep(j, 60) {
      if (dp[x][j] == 0) continue;
      if (j+1<60) add(dp[x-1][j+1], dp[x][j]);
      add(dp[x-1][j], (1LL*(N-1-x)*dp[x][j])%MOD);
    }
  }
  int s = 0;
  rep(b, 60) {
    if (L <= (1LL<<b) && (1LL<<b) <= R) add(s, dp[0][b]);
  }
  if (L == 0) {
    int a = N-1;
    for (int i=1; i<=N-1; i++) a = (1LL*a*i) % MOD;
    add(s, a);
  }
  cout << s << "\n";
  return 0;
}
0