結果

問題 No.660 家を通り過ぎないランダムウォーク問題
ユーザー pazzle1230pazzle1230
提出日時 2018-03-04 13:20:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 225 ms / 2,000 ms
コード長 1,401 bytes
コンパイル時間 1,514 ms
コンパイル使用メモリ 164,432 KB
実行使用メモリ 8,372 KB
最終ジャッジ日時 2023-09-21 12:44:55
合計ジャッジ時間 11,490 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 170 ms
8,180 KB
testcase_01 AC 170 ms
8,148 KB
testcase_02 AC 170 ms
8,128 KB
testcase_03 AC 171 ms
8,084 KB
testcase_04 AC 172 ms
8,108 KB
testcase_05 AC 172 ms
8,136 KB
testcase_06 AC 170 ms
8,136 KB
testcase_07 AC 170 ms
8,096 KB
testcase_08 AC 171 ms
8,108 KB
testcase_09 AC 171 ms
8,184 KB
testcase_10 AC 171 ms
8,356 KB
testcase_11 AC 170 ms
8,116 KB
testcase_12 AC 172 ms
8,140 KB
testcase_13 AC 171 ms
8,300 KB
testcase_14 AC 173 ms
8,132 KB
testcase_15 AC 171 ms
8,244 KB
testcase_16 AC 171 ms
8,108 KB
testcase_17 AC 175 ms
8,092 KB
testcase_18 AC 171 ms
8,112 KB
testcase_19 AC 171 ms
8,100 KB
testcase_20 AC 171 ms
8,092 KB
testcase_21 AC 171 ms
8,136 KB
testcase_22 AC 171 ms
8,132 KB
testcase_23 AC 171 ms
8,084 KB
testcase_24 AC 170 ms
8,104 KB
testcase_25 AC 173 ms
8,184 KB
testcase_26 AC 170 ms
8,116 KB
testcase_27 AC 170 ms
8,092 KB
testcase_28 AC 171 ms
8,088 KB
testcase_29 AC 172 ms
8,200 KB
testcase_30 AC 170 ms
8,096 KB
testcase_31 AC 172 ms
8,092 KB
testcase_32 AC 172 ms
8,092 KB
testcase_33 AC 183 ms
8,184 KB
testcase_34 AC 174 ms
8,144 KB
testcase_35 AC 180 ms
8,180 KB
testcase_36 AC 179 ms
8,184 KB
testcase_37 AC 179 ms
8,128 KB
testcase_38 AC 194 ms
8,148 KB
testcase_39 AC 198 ms
8,132 KB
testcase_40 AC 198 ms
8,092 KB
testcase_41 AC 212 ms
8,184 KB
testcase_42 AC 212 ms
8,080 KB
testcase_43 AC 220 ms
8,088 KB
testcase_44 AC 225 ms
8,372 KB
権限があれば一括ダウンロードができます

ソースコード

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, 200100){
		cat[i] = comb(2*i, i)*mpow(i+1, mod-2)%mod;
		if(i)
			cat[i] = (cat[i]+cat[i-1])%mod;
	}

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

}
0