結果

問題 No.660 家を通り過ぎないランダムウォーク問題
ユーザー pazzle1230pazzle1230
提出日時 2018-03-04 13:18:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,383 bytes
コンパイル時間 1,351 ms
コンパイル使用メモリ 165,228 KB
実行使用メモリ 8,296 KB
最終ジャッジ日時 2023-09-21 12:39:53
合計ジャッジ時間 23,042 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int64 N;
int64 fact[412345] = {};
int64 _cat[212345] = {}, *cat=_cat+1;;
const int64 mod = 1e9+7;

int64 mpow(int64 a, int64 b){
	if(b == 0) return 1;
	if(b%2) return a*mpow(a, b-1)%mod;
	int64 ret = mpow(a, b/2);
	return ret*ret%mod;
}

int64 comb(int64 a, int64 b){
	if(a < 0 || b < 0) return 0;
	return fact[a]*mpow(fact[b], mod-2)%mod*mpow(fact[a-b], mod-2)%mod;
}

int main(void){
	cin >> N;

	fact[0] = 1;
	REP(i, 412344){
		fact[i+1] = (fact[i]*(i+1))%mod;
	}

	int64 x = N/2;
	int64 res = 0;
	int64 now = 0;
	
	REP(i, 212344){
		cat[i] = comb(2*i, i)*mpow(i+1, mod-2)%mod;
		if(i)
			cat[i] += cat[i-1];
	}

	for(int32 i = 0;i < N/2+1;i++){
		res += comb(N+2*i, i);
		if(x-i-1 >= 0)
    		res -= 2*comb(N+2*i, i)*cat[x-i-1];
	}
	cout << res << endl;

}
0