結果

問題 No.660 家を通り過ぎないランダムウォーク問題
ユーザー どららどらら
提出日時 2018-03-26 00:59:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 313 ms / 2,000 ms
コード長 1,148 bytes
コンパイル時間 1,529 ms
コンパイル使用メモリ 164,940 KB
実行使用メモリ 11,496 KB
最終ジャッジ日時 2023-09-07 12:22:00
合計ジャッジ時間 17,640 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 309 ms
11,340 KB
testcase_01 AC 309 ms
11,492 KB
testcase_02 AC 309 ms
11,208 KB
testcase_03 AC 310 ms
11,176 KB
testcase_04 AC 309 ms
11,208 KB
testcase_05 AC 310 ms
11,160 KB
testcase_06 AC 309 ms
11,488 KB
testcase_07 AC 309 ms
11,260 KB
testcase_08 AC 309 ms
11,380 KB
testcase_09 AC 311 ms
11,268 KB
testcase_10 AC 309 ms
11,204 KB
testcase_11 AC 311 ms
11,208 KB
testcase_12 AC 310 ms
11,496 KB
testcase_13 AC 312 ms
11,368 KB
testcase_14 AC 311 ms
11,164 KB
testcase_15 AC 310 ms
11,160 KB
testcase_16 AC 311 ms
11,264 KB
testcase_17 AC 309 ms
11,268 KB
testcase_18 AC 311 ms
11,216 KB
testcase_19 AC 311 ms
11,172 KB
testcase_20 AC 309 ms
11,200 KB
testcase_21 AC 309 ms
11,156 KB
testcase_22 AC 309 ms
11,140 KB
testcase_23 AC 309 ms
11,172 KB
testcase_24 AC 309 ms
11,204 KB
testcase_25 AC 309 ms
11,160 KB
testcase_26 AC 309 ms
11,212 KB
testcase_27 AC 309 ms
11,488 KB
testcase_28 AC 309 ms
11,144 KB
testcase_29 AC 310 ms
11,164 KB
testcase_30 AC 309 ms
11,136 KB
testcase_31 AC 309 ms
11,340 KB
testcase_32 AC 309 ms
11,220 KB
testcase_33 AC 309 ms
11,280 KB
testcase_34 AC 309 ms
11,208 KB
testcase_35 AC 309 ms
11,148 KB
testcase_36 AC 308 ms
11,144 KB
testcase_37 AC 313 ms
11,204 KB
testcase_38 AC 311 ms
11,144 KB
testcase_39 AC 309 ms
11,200 KB
testcase_40 AC 309 ms
11,172 KB
testcase_41 AC 309 ms
11,208 KB
testcase_42 AC 310 ms
11,484 KB
testcase_43 AC 309 ms
11,140 KB
testcase_44 AC 311 ms
11,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

#define MOD 1000000007
#define MX 500005

ll fact[MX];
ll invfact[MX];

ll mod_pow(ll x, ll n, ll mod){
  if(n==0) return 1;
  ll res = mod_pow(x * x % mod, n / 2, mod);
  if(n & 1) res = res * x % mod;
  return res;
}
ll mod_comb(ll n, ll k){
  if(n<0 || k<0 || n<k) return 0;
  return (((fact[n] * invfact[k]) % MOD) * invfact[n-k]) % MOD;
}
void comb_init(){
  fact[0] = fact[1] = 1;
  for(ll i=2; i<MX; i++) fact[i] = (fact[i-1] * i) % MOD;
  invfact[0] = invfact[1] = 1;
  for(ll i=2; i<MX; i++) invfact[i] = mod_pow(fact[i], MOD-2, MOD);
}
int main(){
  comb_init();
  
  int N;
  cin >> N;

  ll ret = 1;
  REP(i,1,N/2+1){
    ll h = i;
    ll w = N-1+i;
    ll tmp1 = mod_comb(h+w, w);
    ll tmp2 = mod_comb(h-1+w+1, w+1);
    ll ans = (tmp1 - tmp2 + MOD)%MOD;
    ret += ans;
    ret %= MOD;
  }

  cout << ret << endl;
  
  return 0;
}
0