結果

問題 No.129 お年玉(2)
ユーザー tubo28tubo28
提出日時 2015-01-17 01:35:23
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 833 ms / 5,000 ms
コード長 1,580 bytes
コンパイル時間 469 ms
コンパイル使用メモリ 65,920 KB
実行使用メモリ 316,796 KB
最終ジャッジ日時 2023-08-18 16:30:19
合計ジャッジ時間 16,468 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
99,340 KB
testcase_01 AC 89 ms
210,916 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 289 ms
203,788 KB
testcase_06 AC 478 ms
256,484 KB
testcase_07 AC 619 ms
289,152 KB
testcase_08 AC 298 ms
213,628 KB
testcase_09 AC 584 ms
274,476 KB
testcase_10 AC 682 ms
292,076 KB
testcase_11 AC 337 ms
228,980 KB
testcase_12 AC 239 ms
215,692 KB
testcase_13 AC 200 ms
211,900 KB
testcase_14 AC 480 ms
262,604 KB
testcase_15 AC 379 ms
237,552 KB
testcase_16 AC 369 ms
241,712 KB
testcase_17 AC 650 ms
279,884 KB
testcase_18 AC 592 ms
274,608 KB
testcase_19 AC 477 ms
249,652 KB
testcase_20 AC 485 ms
268,192 KB
testcase_21 AC 833 ms
316,796 KB
testcase_22 AC 415 ms
241,028 KB
testcase_23 AC 690 ms
296,000 KB
testcase_24 AC 302 ms
227,928 KB
testcase_25 AC 306 ms
223,196 KB
testcase_26 AC 431 ms
232,872 KB
testcase_27 AC 415 ms
232,776 KB
testcase_28 AC 663 ms
307,152 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 7 ms
21,968 KB
testcase_35 AC 10 ms
33,056 KB
testcase_36 AC 12 ms
35,472 KB
testcase_37 AC 14 ms
40,164 KB
testcase_38 AC 81 ms
145,288 KB
testcase_39 AC 136 ms
166,044 KB
testcase_40 AC 384 ms
226,068 KB
testcase_41 AC 206 ms
188,108 KB
testcase_42 AC 98 ms
154,656 KB
testcase_43 AC 86 ms
151,848 KB
testcase_44 AC 622 ms
279,604 KB
testcase_45 AC 60 ms
113,500 KB
testcase_46 AC 114 ms
168,120 KB
testcase_47 AC 784 ms
307,956 KB
testcase_48 AC 335 ms
221,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <utility>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define each(e,c) for(auto&e:c)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<(DUMP(),__VA_ARGS__).str()<<" ["<<__LINE__<<"]"<<endl)
struct DUMP:ostringstream{template<class T>DUMP &operator,(const T&t){if(this->tellp())*this<<", ";*this<<t;return *this;}};
#else
#define dump(...)
#endif
template<class T> ostream& operator<<(ostream& os, vector<T> const& v){
    rep(i,v.size()) os << v[i] << (i+1==v.size()?"":" ");
    return os;
}

const ll mod = 1000000000;
const int MAX_N = 10000;

// nCr % mod
ll nCr(int n, int r){
    static bool done[MAX_N+1][MAX_N/2+2];
    static ll dp[MAX_N+1][MAX_N/2+2];
    if (n < 0 || r < 0 || n < r) return 0;
    if (r==0) return 1;
    if (r > n-r) r = n-r;
    ll &res = dp[n][r];
    if (done[n][r]) return res;
    done[n][r] = true;
    return res = (nCr(n-1,r-1) + nCr(n-1,r))%mod;
}

int main(){
    ll N,M;
    while(cin>>N>>M){
        N/=1000;
        ll rem = N-N/M*M;
        dump(M,rem);
        cout << nCr(M,rem) << endl;
    }
}
0