結果

問題 No.660 家を通り過ぎないランダムウォーク問題
ユーザー chocorusk
提出日時 2018-12-25 00:41:03
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 1,041 bytes
コンパイル時間 1,641 ms
コンパイル使用メモリ 95,496 KB
実行使用メモリ 9,728 KB
最終ジャッジ日時 2024-09-25 11:07:02
合計ジャッジ時間 2,377 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k>0){
        if(k%2==1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k/=2;
    }
    return ans;
}
ll inv(ll a){
	return powmod(a, MOD-2);
}
int main()
{
	int n; cin>>n;
	ll f[400001]; f[0]=1;
	for(ll i=1; i<=2*n; i++) f[i]=f[i-1]*i%MOD;
	ll invf[400001];
	invf[2*n]=inv(f[2*n]);
	for(ll i=2*n-1; i>=0; i--) invf[i]=invf[i+1]*(i+1)%MOD;
	ll ans=1;
	for(int i=1; i<=n/2; i++){
		ans+=(f[n-1+2*i]*invf[i]%MOD*invf[n-1+i]%MOD);
		ans+=(MOD-f[n-1+2*i]*invf[i-1]%MOD*invf[n+i]%MOD);
		ans%=MOD;
	}
	cout<<ans<<endl;
	return 0;
}
0