結果

問題 No.727 仲介人moko
ユーザー mamekinmamekin
提出日時 2018-09-17 16:43:05
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 166 ms / 1,000 ms
コード長 2,005 bytes
コンパイル時間 1,203 ms
コンパイル使用メモリ 118,476 KB
実行使用メモリ 49,652 KB
最終ジャッジ日時 2023-09-25 09:30:44
合計ジャッジ時間 4,111 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 5 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 64 ms
23,708 KB
testcase_15 AC 114 ms
37,656 KB
testcase_16 AC 52 ms
20,240 KB
testcase_17 AC 66 ms
24,332 KB
testcase_18 AC 45 ms
17,264 KB
testcase_19 AC 137 ms
42,316 KB
testcase_20 AC 69 ms
24,144 KB
testcase_21 AC 36 ms
14,228 KB
testcase_22 AC 30 ms
12,432 KB
testcase_23 AC 157 ms
47,272 KB
testcase_24 AC 166 ms
49,652 KB
testcase_25 AC 103 ms
32,848 KB
testcase_26 AC 127 ms
39,536 KB
testcase_27 AC 103 ms
32,872 KB
testcase_28 AC 5 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

void mod_inverse(int n, vector<long long>& inv, int mod)
{
    inv.assign(n+1, -1);
    inv[1] = 1;
    for(int i=2; i<=n; ++i)
        inv[i] = inv[mod % i] * (mod - mod / i) % mod;
}

class FactorialCalculation
{
private:
    const int mod;
    vector<long long> factorial;
    vector<long long> invFactorial;
public:
    FactorialCalculation(int n, int mod) : mod(mod)
    {
        factorial.resize(n+1, 1);
        invFactorial.resize(n+1, 1);
        vector<long long> inv;
        mod_inverse(n, inv, mod);
        for(int i=1; i<=n; ++i){
            factorial[i] = factorial[i-1] * i % mod;
            invFactorial[i] = invFactorial[i-1] * inv[i] % mod;
        }
    }
    long long getFactorial(int n){
        return factorial[n];
    }
    long long getInvFactorial(int n){
        return invFactorial[n];
    }
    long long getPermutation(int n, int r){
        if(n < r)
            return 0;
        return factorial[n] * invFactorial[n-r] % mod;
    }
    long long getCombination(int n, int r){
        if(n < r)
            return 0;
        return getPermutation(n, r) * invFactorial[r] % mod;
    }
    long long getHomogeneous(int n, int r){
        return getCombination(n+r-1, r);
    }
};

const int MOD = 1000000007;

int main()
{
    int n;
    cin >> n;
    FactorialCalculation fc(2*n, MOD);

    long long ans = fc.getFactorial(n);
    for(int i=1; i<=n; ++i){
        ans *= fc.getCombination(2*i, 2);
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}
0