結果

問題 No.1684 Find Brackets
ユーザー SSRSSSRS
提出日時 2021-09-17 22:06:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 218 ms / 2,000 ms
コード長 1,366 bytes
コンパイル時間 1,921 ms
コンパイル使用メモリ 171,940 KB
実行使用メモリ 22,872 KB
最終ジャッジ日時 2023-09-12 07:45:34
合計ジャッジ時間 5,511 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 216 ms
22,548 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 205 ms
22,056 KB
testcase_08 AC 181 ms
20,940 KB
testcase_09 AC 156 ms
19,908 KB
testcase_10 AC 53 ms
7,468 KB
testcase_11 AC 33 ms
6,808 KB
testcase_12 AC 114 ms
13,112 KB
testcase_13 AC 181 ms
20,144 KB
testcase_14 AC 218 ms
22,616 KB
testcase_15 AC 214 ms
22,684 KB
testcase_16 AC 216 ms
22,676 KB
testcase_17 AC 216 ms
22,796 KB
testcase_18 AC 214 ms
22,444 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 214 ms
22,872 KB
testcase_22 AC 216 ms
22,552 KB
testcase_23 AC 215 ms
22,564 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;
	}
}
int main(){
  int N, M;
  cin >> N >> M;
  vector<int> imos(N + 2, 0);
  for (int i = M; i <= N; i++){
    int L = max(N - i * 2, 0) + i;
    int R = N;
    imos[L]++;
    imos[R + 1]--;
  }
  for (int i = 0; i <= N; i++){
    imos[i + 1] += imos[i];
  }
  long long ans = 0;
  for (int i = 0; i <= N; i++){
    long long cnt = modbinom(N, i) - modbinom(N, i + 1) + MOD;
    long long f = i * 2;
    ans += cnt * f % MOD * imos[i] % MOD;
  }
  ans %= MOD;
  cout << ans << endl;
}
0