結果

問題 No.411 昇順昇順ソート
ユーザー renjyaku_intrenjyaku_int
提出日時 2020-09-18 00:47:10
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 179 ms / 2,000 ms
コード長 4,333 bytes
コンパイル時間 2,390 ms
コンパイル使用メモリ 209,600 KB
実行使用メモリ 18,788 KB
最終ジャッジ日時 2023-09-04 08:09:23
合計ジャッジ時間 9,895 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 177 ms
18,760 KB
testcase_01 AC 176 ms
18,708 KB
testcase_02 AC 177 ms
18,740 KB
testcase_03 AC 178 ms
18,784 KB
testcase_04 AC 175 ms
18,528 KB
testcase_05 AC 176 ms
18,632 KB
testcase_06 AC 176 ms
18,524 KB
testcase_07 AC 177 ms
18,644 KB
testcase_08 AC 176 ms
18,504 KB
testcase_09 AC 176 ms
18,668 KB
testcase_10 AC 177 ms
18,788 KB
testcase_11 AC 176 ms
18,532 KB
testcase_12 AC 177 ms
18,688 KB
testcase_13 AC 176 ms
18,528 KB
testcase_14 AC 178 ms
18,748 KB
testcase_15 AC 176 ms
18,400 KB
testcase_16 AC 178 ms
18,664 KB
testcase_17 AC 177 ms
18,660 KB
testcase_18 AC 177 ms
18,728 KB
testcase_19 AC 176 ms
18,672 KB
testcase_20 AC 177 ms
18,636 KB
testcase_21 AC 176 ms
18,524 KB
testcase_22 AC 176 ms
18,664 KB
testcase_23 AC 179 ms
18,736 KB
testcase_24 AC 176 ms
18,632 KB
testcase_25 AC 177 ms
18,740 KB
testcase_26 AC 177 ms
18,448 KB
testcase_27 AC 178 ms
18,728 KB
testcase_28 AC 176 ms
18,660 KB
testcase_29 AC 176 ms
18,520 KB
testcase_30 AC 178 ms
18,644 KB
testcase_31 AC 177 ms
18,696 KB
testcase_32 AC 176 ms
18,700 KB
testcase_33 AC 176 ms
18,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#include <tourist>
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//g++ yarudake.cpp -std=c++17 -I .
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll M = pow(10, 9) + 7;

vector<ll> fac(1000001);  //n!(mod M)
vector<ll> ifac(1000001); //k!^{M-2} (mod M)
ll mpow(ll x, ll n)
{ //x^n(mod M)
    ll ans = 1;
    while (n != 0)
    {
        if (n & 1)
            ans = ans * x % M;
        x = x * x % M;
        n = n >> 1;
    }
    return ans;
}
//conbination
ll comb(ll a, ll b)
{ //aCb(mod M)
    if (a == 0 && b == 0)
        return 1;
    if (a < b || a < 0)
        return 0;
    ll tmp = ifac[a - b] * ifac[b] % M;
    return tmp * fac[a] % M;
}
//素因数分解o√n
map<int, int> prime_factor(int n)
{
    map<int, int> res;
    for (int i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ++res[i];
            n /= i;
        }
    }
    if (n != 1)
        res[n] = 1;
    // for (int i = 2; i <= n; i++)
    //cout << res[i] << "\n";
    return res;
}
//n!
ll fact_mod(ll n)
{
    ll ret = 1;
    for (ll i = 2; i <= n; i++)
        ret = ret * (i % MOD) % MOD;
    return ret;
}

// 繰り返し二乗法
ll pow_mod(ll x, ll n)
{
    if (n == 0)
        return 1;
    ll ret = pow_mod((x * x) % MOD, n / 2);
    if (n & 1)
        ret = (ret * x) % MOD;
    return ret;
}

//nCr O(r) nがでかくても安心
ll combination_mod(ll n, ll r)
{
    if (r > n - r)
        r = n - r;
    if (r == 0)
        return 1;
    ll a = 1;
    //a=n!/(n-r)!=n~n-r+1までの総積->O(r)
    for (ll i = 0; i < r; i++)
        a = a * ((n - i) % MOD) % MOD;
    //b=inv(r!)
    ll b = pow_mod(fact_mod(r), MOD - 2);
    return (a % MOD) * (b % MOD) % MOD;
}

ll inv_mod(ll n)
{
    // フェルマーの小定理
    return pow_mod(n, MOD - 2);
}
const int N_MAX = 1001;
double pascal[N_MAX][N_MAX] = {};

// パスカルの三角形
// 確率Ver
// n段目は 2^n で割った値が入る (横の和 = 1)

void calc_pascal()
{
    FOR(i, 0, N_MAX)
    {
        pascal[i][0] = 1.0 / pow(2.0f, i);
    }
    pascal[1][1] = 1.0 / 2.0;

    FOR(i, 2, N_MAX)
    {
        for (int j = 1; j <= i; j++)
        {
            pascal[i][j] = pascal[i - 1][j] + pascal[i - 1][j - 1];
            pascal[i][j] /= 2.0;
        }
    }
}
//kが大きいときにO(n)でi+kCi (0<i<n)
vector<ll> comb_recur(ll n, ll k)
{
    vector<ll> res(n, 1);
    for (ll i = 1; i < n; i++)
    {
        res[i] *= (k + i);
        res[i] %= MOD;
        res[i] *= inv_mod(i);
        res[i] %= MOD;
        res[i] *= res[i - 1];
        res[i] %= MOD;
    }
    return res;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin>>n>>k;
    fac[0] = 1;
    ifac[0] = 1;
    for (ll i = 0; i < 1000000; i++)
    {
        fac[i + 1] = fac[i] * (i + 1) % M;              // n!(mod M)
        ifac[i + 1] = ifac[i] * mpow(i + 1, M - 2) % M; // k!^{M-2} (mod M)
    }
    ll ans=0;
    if(k!=1){
        ans++;
    }
    for(int i=0;i<=n-2;i++){
        for(int j=k+1;j<=n;j++){
            int c=comb(j-k-1,i);
            if(k==1&&j-k-1==i)c--;
            ans+=c;
        }
    }
    cout<<ans<<"\n";
}
0