結果

問題 No.834 Random Walk Trip
ユーザー 00 Sakuda00 Sakuda
提出日時 2024-03-31 03:32:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 351 ms / 2,000 ms
コード長 640 bytes
コンパイル時間 2,247 ms
コンパイル使用メモリ 205,916 KB
実行使用メモリ 11,108 KB
最終ジャッジ日時 2024-03-31 03:32:21
合計ジャッジ時間 4,137 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 4 ms
6,676 KB
testcase_03 AC 16 ms
7,200 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 15 ms
7,200 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 1 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 1 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 4 ms
6,676 KB
testcase_18 AC 11 ms
6,676 KB
testcase_19 AC 32 ms
11,108 KB
testcase_20 AC 17 ms
7,368 KB
testcase_21 AC 20 ms
7,504 KB
testcase_22 AC 7 ms
6,676 KB
testcase_23 AC 275 ms
6,676 KB
testcase_24 AC 4 ms
6,676 KB
testcase_25 AC 351 ms
7,200 KB
権限があれば一括ダウンロードができます

ソースコード

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