結果

問題 No.645 Count Permutation
ユーザー vjudge1
提出日時 2025-01-27 22:38:15
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 98 ms / 2,000 ms
コード長 884 bytes
コンパイル時間 2,556 ms
コンパイル使用メモリ 161,896 KB
実行使用メモリ 53,632 KB
最終ジャッジ日時 2025-01-27 22:38:20
合計ジャッジ時間 4,096 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 1e5 + 10;
const int LG = 64;
ll n, l, r;
ll dp[LG][N];
int main(int argc, char const *argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cin >> n >> l >> r;
    dp[0][n] = 1;
    for (int i = n - 1; i >= 1; i--)
    {
        for (int j = 0; j < LG; j++)
        {
            (dp[j][i] += dp[j][i + 1] * (n - 1 - i)) %= mod;
            if (j < LG - 1)
                (dp[j + 1][i] += dp[j][i + 1]) %= mod;
        }
    }
    ll c0 = n - 1;
    for (int i = 1; i <= n - 1; i++)
        (c0 *= i) %= mod;
    ll ans = (l ? 0 : c0);
    for (int i = 1; i < LG; i++)
    {
        if ((1ll << i) < l || r < (1ll << i))
            continue;
        (ans += dp[i][1]) %= mod;
    }
    cout << ans << endl;
    return 0;
}
0