結果

問題 No.1785 Inequality Signs
ユーザー XDXD
提出日時 2021-12-18 09:06:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 2,261 bytes
コンパイル時間 1,561 ms
コンパイル使用メモリ 165,424 KB
実行使用メモリ 5,304 KB
最終ジャッジ日時 2023-10-13 12:56:49
合計ジャッジ時間 3,928 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 6 ms
4,348 KB
testcase_02 AC 23 ms
4,772 KB
testcase_03 AC 30 ms
4,960 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 14 ms
4,352 KB
testcase_06 AC 28 ms
4,812 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 26 ms
4,824 KB
testcase_09 AC 6 ms
4,352 KB
testcase_10 AC 19 ms
4,416 KB
testcase_11 AC 7 ms
4,352 KB
testcase_12 AC 12 ms
4,348 KB
testcase_13 AC 5 ms
4,352 KB
testcase_14 AC 16 ms
4,456 KB
testcase_15 AC 12 ms
4,352 KB
testcase_16 AC 10 ms
4,352 KB
testcase_17 AC 20 ms
4,696 KB
testcase_18 AC 20 ms
4,484 KB
testcase_19 AC 18 ms
4,352 KB
testcase_20 AC 18 ms
4,352 KB
testcase_21 AC 16 ms
4,348 KB
testcase_22 AC 6 ms
4,352 KB
testcase_23 AC 9 ms
4,348 KB
testcase_24 AC 29 ms
4,908 KB
testcase_25 AC 13 ms
4,348 KB
testcase_26 AC 12 ms
4,348 KB
testcase_27 AC 30 ms
4,968 KB
testcase_28 AC 31 ms
4,988 KB
testcase_29 AC 30 ms
5,044 KB
testcase_30 AC 30 ms
5,304 KB
testcase_31 AC 31 ms
5,040 KB
testcase_32 AC 31 ms
5,080 KB
testcase_33 AC 1 ms
4,352 KB
testcase_34 AC 3 ms
4,352 KB
testcase_35 AC 2 ms
4,352 KB
testcase_36 AC 18 ms
4,768 KB
testcase_37 AC 7 ms
4,980 KB
testcase_38 AC 7 ms
4,756 KB
testcase_39 AC 5 ms
4,348 KB
testcase_40 AC 7 ms
4,348 KB
testcase_41 AC 9 ms
4,348 KB
testcase_42 AC 20 ms
5,048 KB
testcase_43 AC 28 ms
5,052 KB
testcase_44 AC 23 ms
4,768 KB
testcase_45 AC 5 ms
4,352 KB
testcase_46 AC 7 ms
4,724 KB
testcase_47 AC 5 ms
4,348 KB
testcase_48 AC 10 ms
4,448 KB
testcase_49 AC 2 ms
4,352 KB
testcase_50 AC 22 ms
4,716 KB
testcase_51 AC 3 ms
4,348 KB
testcase_52 AC 3 ms
4,352 KB
testcase_53 AC 5 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

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 ll = max(k - n, 0), rr = max(k - 1, 0) - 1;
	int l = ll, r = ll - 1;
//	printf("[%d, %d]\n", l, r);
	while (r <= rr) ++r, (r && (tmp *= Mint(r), 0));
	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;
//		if (a == 1) printf("%d %d\n", ll, rr);
		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