結果

問題 No.834 Random Walk Trip
ユーザー 00 Sakuda
提出日時 2024-03-31 03:32:17
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 355 ms / 2,000 ms
コード長 640 bytes
コンパイル時間 2,221 ms
コンパイル使用メモリ 198,176 KB
最終ジャッジ日時 2025-02-20 16:06:53
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/modint>
using namespace std;
using namespace atcoder;
using ll = long long;
using mint = modint;
int main() {
	mint::set_mod((ll)1e9 + 7);
	int N, M;cin >> N >> M;
	vector<mint> fac(N + M + 1, 1);
	for (int i = 1;i <= N + M;i++) fac[i] = i * fac[i - 1];
	mint ans = 0;
	if (N == 1) {
		cout << 1 << endl;
		return 0;
	}
	for (int l = 0;l <= M;l++) {
		int r = M - l;
		int mod = ((r - l + (2 * N) % (2 * N)) + (2* N)) % (2 * N);
		//cout <<r << " " << l << " " << mod << endl;
		if (mod == 0 or mod == (2 * N) - 1) ans += fac[M] * fac[l].inv() * fac[M - l].inv();
	}
	cout << ans.val() << endl;
}
0