結果

問題 No.1785 Inequality Signs
ユーザー SSRSSSRS
提出日時 2021-12-14 00:06:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 113 ms / 2,000 ms
コード長 2,028 bytes
コンパイル時間 1,870 ms
コンパイル使用メモリ 171,984 KB
実行使用メモリ 19,304 KB
最終ジャッジ日時 2023-09-30 06:05:55
合計ジャッジ時間 6,205 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 16 ms
5,420 KB
testcase_02 AC 80 ms
18,200 KB
testcase_03 AC 107 ms
19,128 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 45 ms
11,120 KB
testcase_06 AC 97 ms
18,896 KB
testcase_07 AC 5 ms
4,380 KB
testcase_08 AC 93 ms
18,344 KB
testcase_09 AC 17 ms
5,408 KB
testcase_10 AC 65 ms
12,200 KB
testcase_11 AC 21 ms
6,728 KB
testcase_12 AC 39 ms
10,656 KB
testcase_13 AC 15 ms
5,216 KB
testcase_14 AC 52 ms
11,288 KB
testcase_15 AC 44 ms
10,692 KB
testcase_16 AC 30 ms
7,132 KB
testcase_17 AC 66 ms
12,416 KB
testcase_18 AC 66 ms
12,404 KB
testcase_19 AC 54 ms
11,304 KB
testcase_20 AC 59 ms
11,948 KB
testcase_21 AC 54 ms
11,780 KB
testcase_22 AC 20 ms
6,744 KB
testcase_23 AC 29 ms
7,144 KB
testcase_24 AC 103 ms
19,108 KB
testcase_25 AC 41 ms
10,768 KB
testcase_26 AC 41 ms
10,760 KB
testcase_27 AC 108 ms
19,304 KB
testcase_28 AC 113 ms
19,176 KB
testcase_29 AC 112 ms
19,164 KB
testcase_30 AC 108 ms
19,104 KB
testcase_31 AC 110 ms
19,180 KB
testcase_32 AC 107 ms
19,232 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 6 ms
4,376 KB
testcase_35 AC 15 ms
5,552 KB
testcase_36 AC 93 ms
18,384 KB
testcase_37 AC 103 ms
19,180 KB
testcase_38 AC 91 ms
18,688 KB
testcase_39 AC 24 ms
6,920 KB
testcase_40 AC 35 ms
10,608 KB
testcase_41 AC 57 ms
11,716 KB
testcase_42 AC 102 ms
19,164 KB
testcase_43 AC 107 ms
19,064 KB
testcase_44 AC 89 ms
18,348 KB
testcase_45 AC 36 ms
10,792 KB
testcase_46 AC 84 ms
18,260 KB
testcase_47 AC 51 ms
11,260 KB
testcase_48 AC 65 ms
12,484 KB
testcase_49 AC 4 ms
4,380 KB
testcase_50 AC 86 ms
18,452 KB
testcase_51 AC 9 ms
4,376 KB
testcase_52 AC 6 ms
4,376 KB
testcase_53 AC 13 ms
5,340 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
long long modpow(long long a, long long b){
	long long ans = 1;
	while (b > 0){
		if (b % 2 == 1){
			ans *= a;
			ans %= MOD;
		}
		a *= a;
		a %= MOD;
		b /= 2;
	}
	return ans;
}
long long modinv(long long a){
	return modpow(a, MOD - 2);
}
vector<long long> mf = {1};
vector<long long> mfi = {1};
long long modfact(int n){
	if (mf.size() > n){
		return mf[n];
	} else {
		for (int i = mf.size(); i <= n; i++){
			long long next = mf.back() * i % MOD;
			mf.push_back(next);
			mfi.push_back(modinv(next));
		}
		return mf[n];
	}
}
long long modfactinv(int n){
	if (mfi.size() > n){
		return mfi[n];
	} else {
		return modinv(modfact(n));
	}
}
long long modbinom(int n, int k){
	if (n < 0 || k < 0 || k > n){
		return 0;
	} else {
		return modfact(n) * modfactinv(k) % MOD * modfactinv(n - k) % MOD;
	}
}
template <typename T>
struct segment_tree{
	int N;
	vector<T> ST;
	segment_tree(vector<T> A){
		int n = A.size();
		N = 1;
		while (N < n){
			N *= 2;
		}
		ST = vector<T>(N * 2 - 1, 1);
		for (int i = 0; i < n; i++){
			ST[N - 1 + i] = A[i];
		}
		for (int i = N - 2; i >= 0; i--){
			ST[i] = ST[i * 2 + 1] * ST[i * 2 + 2] % MOD;
		}
	}
	T operator [](int k){
		return ST[N - 1 + k];
	}
	T range_product(int L, int R, int i, int l, int r){
		if (R <= l || r <= L){
			return 1;
		} else if (L <= l && r <= R){
			return ST[i];
		} else {
			int m = (l + r) / 2;
			return range_product(L, R, i * 2 + 1, l, m) * range_product(L, R, i * 2 + 2, m, r) % MOD;;
		}
	}
	T range_product(int L, int R){
		return range_product(L, R, 0, 0, N);
	}
};
int main(){
  int N, K;
  cin >> N >> K;
  long long ans = 0;
  //K+i, K+i-1, ..., K+i-N+1
  //K-N+1~K+N-1
  vector<long long> A(N * 2);
  for (int i = 0; i < N * 2; i++){
    A[i] = K - N + 1 + i;
  }
  segment_tree<long long> ST(A);
  for (int i = 0; i <= N - 1; i++){
    ans += modbinom(N - 1, i) * ST.range_product(i, i + N) % MOD * modfactinv(N) % MOD;
  }
  ans %= MOD;
  cout << ans << endl;
}
0