結果

問題 No.1785 Inequality Signs
ユーザー XDXD
提出日時 2021-12-18 09:00:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,205 bytes
コンパイル時間 2,025 ms
コンパイル使用メモリ 166,516 KB
実行使用メモリ 8,700 KB
最終ジャッジ日時 2023-10-13 12:50:35
合計ジャッジ時間 5,874 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 19 ms
4,348 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define forn(i,s,t) for(int i = (s); i <= (t); ++i)
#define form(i,s,t) for(int i = (s); i >= (t); --i)
#define rep(i,s,t) for(int i = (s); i < (t); ++i)
using namespace std;
const int N = 2e5 + 5, Mod = 1e9 + 7;
namespace Modint {
	struct Mint {
		int res;
		Mint() {}
		Mint(int _r) : res(_r) {}
		inline friend Mint operator + (const Mint& A, const Mint& B) {
			return Mint((A.res + B.res >= Mod) ? (A.res + B.res - Mod) : (A.res + B.res));
		}
		inline friend Mint operator - (const Mint& A, const Mint& B) {return A + Mint(Mod - B.res); }
		inline friend Mint operator * (const Mint& A, const Mint& B) {return Mint(1ll * A.res * B.res % Mod); }
		inline friend Mint& operator += (Mint& A, const Mint& B) {return A = A + B; }
		inline friend Mint& operator -= (Mint& A, const Mint& B) {return A = A - B; }
		inline friend Mint& operator *= (Mint& A, const Mint& B) {return A = A * B; }
		inline friend Mint q_pow(Mint p, int k = Mod - 2) {
			Mint res(1);
			for (; k; k >>= 1, p *= p) (k & 1) && (res *= p, 0);
			return res;
		}
	} ;
}
using Modint :: Mint;
Mint fac[N], ifac[N];
inline void table(int n) {
	fac[0] = Mint(1);
	forn (i, 1, n) fac[i] = fac[i - 1] * Mint(i);
	ifac[n] = q_pow(fac[n]);
	form (i, n - 1, 0) ifac[i] = ifac[i + 1] * Mint(i + 1);
}
inline bool check(int n, int r) {return n - r >= 0 && n >= 0 && r >= 0; }
inline Mint C(int n, int r) {
	if (!check(n, r)) return Mint(0);
	return fac[n] * ifac[r] * ifac[n - r];
}
int n, k;
int main() {
	scanf("%d%d", &n, &k), table(n);
	Mint res(0), tmp(1); int l = 0, r = 0; int ll = max(k - n, 0), rr = max(k - 1, 0) - 1;
	while (r <= rr) ++r, tmp *= Mint(r);
	while (l <= ll) (l && (tmp *= q_pow(Mint(l)), 0)), ++l;
//		printf("[%d, %d] %d\n", l, r, tmp.res);
	forn (a, 1, n) {
		ll = a + k - n, rr = a + k - 1;
//		printf("%d %d\n", a + k - 1, n);
		if (check(a + k - 1, n)) {
			while (r < rr) ++r, tmp *= Mint(r);
			while (l < ll) tmp *= q_pow(Mint(l)), ++l;
		} else continue ;
//		printf("[%d, %d] %d %d %d\n", l, r, tmp.res, C(n - 1, a - 1).res, ifac[n].res);
//		printf("%d\n", (C(n - 1, a - 1) * tmp * ifac[n]).res);
		res += C(n - 1, a - 1) * tmp * ifac[n];
	}
	printf("%d\n", res.res);
	return 0;
}
0