結果

問題 No.660 家を通り過ぎないランダムウォーク問題
ユーザー ryoissyryoissy
提出日時 2018-03-02 23:54:19
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 747 bytes
コンパイル時間 1,635 ms
コンパイル使用メモリ 144,264 KB
実行使用メモリ 16,036 KB
最終ジャッジ日時 2023-09-05 02:10:29
合計ジャッジ時間 4,684 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
15,780 KB
testcase_01 AC 14 ms
15,968 KB
testcase_02 AC 15 ms
15,844 KB
testcase_03 AC 14 ms
15,712 KB
testcase_04 AC 15 ms
15,720 KB
testcase_05 AC 15 ms
15,816 KB
testcase_06 AC 16 ms
15,812 KB
testcase_07 AC 15 ms
15,756 KB
testcase_08 AC 15 ms
15,872 KB
testcase_09 AC 15 ms
15,876 KB
testcase_10 AC 14 ms
15,812 KB
testcase_11 AC 14 ms
15,712 KB
testcase_12 AC 14 ms
15,756 KB
testcase_13 AC 15 ms
15,752 KB
testcase_14 AC 15 ms
15,796 KB
testcase_15 AC 14 ms
15,756 KB
testcase_16 AC 14 ms
15,748 KB
testcase_17 AC 15 ms
15,812 KB
testcase_18 AC 15 ms
15,708 KB
testcase_19 AC 15 ms
15,828 KB
testcase_20 AC 15 ms
15,776 KB
testcase_21 AC 14 ms
15,748 KB
testcase_22 AC 14 ms
15,736 KB
testcase_23 AC 14 ms
15,844 KB
testcase_24 AC 15 ms
15,904 KB
testcase_25 AC 14 ms
15,728 KB
testcase_26 AC 14 ms
15,732 KB
testcase_27 AC 15 ms
15,836 KB
testcase_28 AC 15 ms
15,744 KB
testcase_29 AC 15 ms
15,876 KB
testcase_30 AC 16 ms
15,908 KB
testcase_31 AC 16 ms
15,824 KB
testcase_32 AC 17 ms
15,728 KB
testcase_33 AC 18 ms
15,728 KB
testcase_34 AC 18 ms
15,736 KB
testcase_35 AC 26 ms
15,812 KB
testcase_36 AC 26 ms
16,032 KB
testcase_37 AC 27 ms
15,840 KB
testcase_38 AC 47 ms
15,780 KB
testcase_39 AC 48 ms
15,820 KB
testcase_40 AC 49 ms
15,720 KB
testcase_41 AC 72 ms
15,808 KB
testcase_42 AC 72 ms
16,036 KB
testcase_43 AC 81 ms
15,752 KB
testcase_44 AC 90 ms
15,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;


ll fact[15000005];

ll extgcd(ll a,ll b,ll& x,ll& y){
	ll d=a;
	if(b!=0LL){
		d=extgcd(b,a%b,y,x);
		y-=(a/b)*x;
	}else{
		x=1;
		y=0;
	}
	return d;
}

ll mod_inverse(ll a,ll m){
	ll x,y;
	extgcd(a,m,x,y);
	return (m+x%m)%m;
}


int main(void){
	fact[0]=1;
	for(ll i=1;i<=1400000;i++){
		fact[i]=fact[i-1]*i%MOD;
	}
	int n;
	scanf("%d",&n);
	ll ans=0;
	for(int i=0;i*2<=n;i++){
		if(i==0)ans++;
		if(i==1){
			ans+=n;
		}
		if(i>=2){
			ll val=fact[n+i*2-1];
			val=val*mod_inverse(fact[n+i],MOD)%MOD;
			val=(ll)val*n%MOD;
			val=val*mod_inverse(fact[i],MOD)%MOD;
			ans=(ans+val)%MOD;
		}
	}
	printf("%d\n",ans);
	return 0;
}
0