結果

問題 No.411 昇順昇順ソート
ユーザー tactac
提出日時 2019-08-02 16:07:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,511 bytes
コンパイル時間 1,407 ms
コンパイル使用メモリ 164,156 KB
実行使用メモリ 15,576 KB
最終ジャッジ日時 2023-09-18 18:15:56
合計ジャッジ時間 3,111 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
15,332 KB
testcase_01 AC 13 ms
15,344 KB
testcase_02 AC 13 ms
15,296 KB
testcase_03 AC 13 ms
15,400 KB
testcase_04 AC 13 ms
15,264 KB
testcase_05 AC 13 ms
15,296 KB
testcase_06 AC 13 ms
15,300 KB
testcase_07 AC 13 ms
15,268 KB
testcase_08 AC 14 ms
15,360 KB
testcase_09 AC 13 ms
15,312 KB
testcase_10 AC 13 ms
15,320 KB
testcase_11 AC 13 ms
15,324 KB
testcase_12 AC 13 ms
15,456 KB
testcase_13 AC 13 ms
15,288 KB
testcase_14 AC 13 ms
15,372 KB
testcase_15 AC 14 ms
15,332 KB
testcase_16 AC 13 ms
15,312 KB
testcase_17 AC 13 ms
15,272 KB
testcase_18 AC 13 ms
15,328 KB
testcase_19 AC 14 ms
15,576 KB
testcase_20 AC 14 ms
15,296 KB
testcase_21 AC 13 ms
15,380 KB
testcase_22 AC 13 ms
15,300 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 WA -
testcase_25 AC 13 ms
15,500 KB
testcase_26 AC 13 ms
15,268 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 14 ms
15,312 KB
testcase_30 AC 14 ms
15,344 KB
testcase_31 AC 13 ms
15,508 KB
testcase_32 AC 14 ms
15,420 KB
testcase_33 AC 13 ms
15,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define out(a) cout << a << endl
#define outa(a, n) rep(_, n) cout << a[_] << " "; cout << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
#define FIX(a) fixed << setprecision(a)
string str;
int n, c, d, k;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}



int main() {
    cin >> n >> k;
    // sample 3, 5 3
    if (k == 1) { out(0); return 0; }
    c = 1; // 3 1 2 4 5
    c += n - k; // 3 4, 3 5
    // 3 4 5
    COMinit();
    rep3(i, 2, n) {
        ll tmp = COM(n - k, i);
        if (tmp <= 0) break;
        c += tmp;
    }
    out(c);
}
0