結果

問題 No.834 Random Walk Trip
ユーザー edamame882edamame882
提出日時 2019-05-25 00:32:54
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 602 ms / 2,000 ms
コード長 2,020 bytes
コンパイル時間 2,663 ms
コンパイル使用メモリ 168,516 KB
実行使用メモリ 19,416 KB
最終ジャッジ日時 2023-10-17 15:11:17
合計ジャッジ時間 15,704 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 589 ms
19,372 KB
testcase_05 AC 591 ms
19,372 KB
testcase_06 AC 591 ms
19,372 KB
testcase_07 AC 590 ms
19,372 KB
testcase_08 AC 589 ms
19,372 KB
testcase_09 AC 591 ms
19,372 KB
testcase_10 AC 590 ms
19,372 KB
testcase_11 AC 591 ms
19,372 KB
testcase_12 AC 592 ms
19,372 KB
testcase_13 AC 591 ms
19,372 KB
testcase_14 AC 590 ms
19,416 KB
testcase_15 AC 589 ms
19,416 KB
testcase_16 AC 590 ms
19,416 KB
testcase_17 AC 590 ms
19,416 KB
testcase_18 AC 590 ms
19,416 KB
testcase_19 AC 590 ms
19,416 KB
testcase_20 AC 590 ms
19,416 KB
testcase_21 AC 590 ms
19,416 KB
testcase_22 AC 589 ms
19,416 KB
testcase_23 AC 599 ms
19,416 KB
testcase_24 AC 590 ms
19,416 KB
testcase_25 AC 602 ms
19,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

ll mod = 1e9 + 7;
//---------------------------------------------------------------------------------------------------
ll f[1010101], rf[1010101];
ll inv(ll x) {
    ll res = 1;
    ll k = mod - 2;
    ll y = x;
    while (k) {
        if (k & 1) res = (res * y) % mod;
        y = (y * y) % mod;
        k /= 2;
    }
    return res;
}
void init() {
    f[0] = 1;
    FOR(i, 1, 1010101) f[i] = (f[i - 1] * i) % mod;
    FOR(i, 0, 1010101) rf[i] = inv(f[i]);
}
//---------------------------------------------------------------------------------------------------
ll modCombi(int n, int k) {
    ll a = f[n]; // = n!
    ll b = rf[n-k]; // = (n-k)!
    ll c = rf[k]; // = k!

    ll bc = (b * c) % mod;

    return (a * bc) % mod;
}
//---------------------------------------------------------------------------------------------------

int main(void)
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,k;
	cin >> n >> k;

  ll ans = 0;
  VLL array;

  if(n == 1){
    cout << 1 << endl;
    return 0;
  }
  init();
  for(int  i= k / 2 % n; i <= k; i += n){
        ans+=modCombi(k, i);
        ans%=MOD;
  }

  cout << ans << endl;
	return 0;
}
0