結果

問題 No.645 Count Permutation
ユーザー yosupotyosupot
提出日時 2017-09-12 05:55:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,574 bytes
コンパイル時間 1,080 ms
コンパイル使用メモリ 111,008 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-25 06:26:37
合計ジャッジ時間 2,531 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
5,248 KB
testcase_01 AC 14 ms
5,376 KB
testcase_02 AC 16 ms
5,376 KB
testcase_03 WA -
testcase_04 AC 16 ms
5,376 KB
testcase_05 AC 15 ms
5,376 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 15 ms
5,376 KB
testcase_22 WA -
testcase_23 AC 16 ms
5,376 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 17 ms
5,376 KB
testcase_32 AC 17 ms
5,376 KB
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

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];
Mint kaku[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];
    }
    kaku[0] = Mint(1);
    kaku[1] = Mint(0);
    for (int i = 2; i < MN; i++) {
        kaku[i] = Mint(i-1) * (kaku[i-2] + kaku[i-1]);
    }
}

Mint C(int n, int k) {
    if (n < k || n < 0) return Mint(0);
    return fact[n] * iFac[k] * iFac[n-k]; 
}

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