結果

問題 No.645 Count Permutation
ユーザー yosupotyosupot
提出日時 2017-09-12 14:31:47
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 2,593 bytes
コンパイル時間 1,022 ms
コンパイル使用メモリ 111,808 KB
実行使用メモリ 4,440 KB
最終ジャッジ日時 2023-08-30 01:52:05
合計ジャッジ時間 3,073 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
4,380 KB
testcase_01 AC 15 ms
4,380 KB
testcase_02 AC 16 ms
4,376 KB
testcase_03 AC 15 ms
4,376 KB
testcase_04 AC 16 ms
4,376 KB
testcase_05 AC 16 ms
4,380 KB
testcase_06 AC 15 ms
4,384 KB
testcase_07 AC 16 ms
4,380 KB
testcase_08 AC 15 ms
4,380 KB
testcase_09 AC 15 ms
4,376 KB
testcase_10 AC 15 ms
4,380 KB
testcase_11 AC 18 ms
4,380 KB
testcase_12 AC 16 ms
4,376 KB
testcase_13 AC 17 ms
4,380 KB
testcase_14 AC 16 ms
4,376 KB
testcase_15 AC 24 ms
4,376 KB
testcase_16 AC 22 ms
4,380 KB
testcase_17 AC 32 ms
4,424 KB
testcase_18 AC 21 ms
4,380 KB
testcase_19 AC 33 ms
4,380 KB
testcase_20 AC 33 ms
4,440 KB
testcase_21 AC 29 ms
4,380 KB
testcase_22 AC 16 ms
4,380 KB
testcase_23 AC 15 ms
4,376 KB
testcase_24 AC 33 ms
4,376 KB
testcase_25 AC 24 ms
4,380 KB
testcase_26 AC 30 ms
4,380 KB
testcase_27 AC 23 ms
4,380 KB
testcase_28 AC 21 ms
4,380 KB
testcase_29 AC 29 ms
4,376 KB
testcase_30 AC 28 ms
4,380 KB
testcase_31 AC 30 ms
4,376 KB
testcase_32 AC 20 ms
4,376 KB
testcase_33 AC 20 ms
4,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <numeric>
#include <random>
#include <vector>
#include <array>
#include <bitset>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <complex>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

template<class T>
T pow(T x, ll n, T r = 1) {
    while (n) {
        if (n & 1) r *= x;
        x *= x;
        n >>= 1;
    }
    return r;
}

template<uint MD>
struct ModInt {
    uint v;
    ModInt() : v{0} {}
    ModInt(ll v) : v{normS(v%MD+MD)} {}
    explicit operator bool() const {return v != 0;}
    static uint normS(const uint &x) {return (x<MD)?x:x-MD;};
    static ModInt make(const uint &x) {ModInt m; m.v = x; return m;}
    static ModInt inv(const ModInt &x) {return pow(ModInt(x), MD-2);} 
    ModInt operator+(const ModInt &r) const {return make(normS(v+r.v));}
    ModInt operator-(const ModInt &r) const {return make(normS(v+MD-r.v));}
    ModInt operator*(const ModInt &r) const {return make((ull)v*r.v%MD);}
    ModInt operator/(const ModInt &r) const {return *this*inv(r);}
    ModInt& operator+=(const ModInt &r) {return *this=*this+r;}
    ModInt& operator-=(const ModInt &r) {return *this=*this-r;}
    ModInt& operator*=(const ModInt &r) {return *this=*this*r;}
    ModInt& operator/=(const ModInt &r) {return *this=*this/r;}
};
using Mint = ModInt<TEN(9)+7>;

const int MN = TEN(5) + TEN(3);

Mint fact[MN], iFac[MN];

void first() {
    fact[0] = Mint(1);
    for (int i = 1; i < MN; i++) {
        fact[i] = fact[i-1] * i;
    }
    for (int i = 0; i < MN; i++) {
        iFac[i] = Mint(1)/fact[i];
    }
}

int main() {
    first();
    int n; ll l, r;
    cin >> n >> l >> r;
    Mint ans = 0;
    if (l == 0) {
        ans += fact[n] - fact[n-1];
    }
    V<Mint> dp(80);
    dp[0] = 1;
    for (int i = 1; i <= n-2; i++) {
        for (int j = 79; j >= 0; j--) {
            dp[j] *= i;
            if (j) dp[j] += dp[j-1];
        }
/*        for (int j = 0; j <= 5; j++) {
            cout << dp[j].v << ", ";
        }
        cout << endl;*/
    }
    for (int i = 1; i <= 61; i++) {
        ll u = 1LL << i;
        if (l <= u && u <= r) {
//            cout << "OK " << i << endl;
            ans += dp[i-1];
        }
    }
    cout << ans.v << endl;
    return 0;
}
0