結果
| 問題 | 
                            No.129 お年玉(2)
                             | 
                    
| コンテスト | |
| ユーザー | 
                             troro_kelp
                         | 
                    
| 提出日時 | 2018-10-08 00:53:26 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 426 ms / 5,000 ms | 
| コード長 | 1,558 bytes | 
| コンパイル時間 | 854 ms | 
| コンパイル使用メモリ | 96,324 KB | 
| 実行使用メモリ | 395,264 KB | 
| 最終ジャッジ日時 | 2024-11-28 01:12:30 | 
| 合計ジャッジ時間 | 22,377 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 46 | 
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
#include <list>
#include <deque>
#include <sstream>
using namespace std;
const constexpr int INF = 1e9;
#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
typedef long long ll;
typedef vector<int> VI;
typedef pair<ll, ll> P;
struct Less{
   bool operator()(const pair<string, int>&a, const pair<string, int>&b){
        if(a.first==b.first){
            return a.second < b.second;
        }
       return a.first < b.first;
    }
};
const constexpr ll MOD = 1e9;
ll extGCD(ll a, ll b, ll& x, ll& y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a/b*x;
    return d;
}
ll GCD(ll a, ll b){
    if(b==0) return a;
    return GCD(b, a%b);
}
ll comb[10010][5010];
int main() {
    ll N, M;
    cin >> N >> M;
    ll r = (N - (((N/M)/1000)*1000*M))/1000; // ←ほんまか?
    
    for(int i=0; i<10010; ++i){
        comb[i][0] = 1;
    }
    for(int i=0; i<5010; ++i){
        comb[i][i]=1;
    }
    for(int i=1; i<10010; ++i){
        for(int j=1; j<5010; ++j){
            comb[i][j] = ((comb[i-1][j-1]%MOD)+(comb[i-1][j]%MOD))%MOD;
        }
    }
    if(M<2*r) cout << comb[M][M-r] << endl;
    else cout << comb[M][r] << endl;
    return 0;
}
            
            
            
        
            
troro_kelp