結果

問題 No.660 家を通り過ぎないランダムウォーク問題
コンテスト
ユーザー vjudge1
提出日時 2026-04-12 19:53:59
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 687 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 909 ms
コンパイル使用メモリ 147,692 KB
実行使用メモリ 9,856 KB
最終ジャッジ日時 2026-04-12 19:54:02
合計ジャッジ時間 2,645 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<iostream>
using namespace std;
#define int long long
const int N = 4e5 + 5;
const int mod = 1e9 + 7;

int n,fac[N],inv[N];

int qpow(int a,int b)
{
	int res = 1;
	while(b)
	{
		if(b & 1) res = res * a % mod;
		a = a * a % mod; b >>= 1;
	}
	return res;
}

int c(int x,int y)
{
	if(x < 0 || y < 0 || x < y) return 0;
	return fac[x] * inv[y] % mod * inv[x-y] % mod;
}

signed main()
{
	fac[0] = 1; for(int i=1;i<N;i++) fac[i] = fac[i-1] * i % mod;
	inv[N-1] = qpow(fac[N-1],mod-2); for(int i=N-2;i>=0;i--) inv[i] = inv[i+1] * (i + 1) % mod;
	cin >> n; int ans = 0;
	for(int i=0;i<=n/2;i++) ans = (ans + c(n+2*i-1,i) + mod - c(n+2*i-1,n+i)) % mod;
	cout << ans << '\n';
	return 0;
}
0