結果
| 問題 |
No.129 お年玉(2)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-01-16 23:35:49 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 562 ms / 5,000 ms |
| コード長 | 637 bytes |
| コンパイル時間 | 1,416 ms |
| コンパイル使用メモリ | 164,804 KB |
| 実行使用メモリ | 101,164 KB |
| 最終ジャッジ日時 | 2024-11-27 22:56:02 |
| 合計ジャッジ時間 | 11,948 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 46 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = (int)1e9;
ll N,M,W,H;
int combination_mod(int n, int m, int s=0){
static vector<vector<int> > c;
if(n<0||m<0||n<m)return 0;
m=min(m,n-m);
if((int)c.size()<=n)c.resize(n+1);
if((int)c[n].size()==0) c[n].resize(n/2+1);
if(c[n][m]!=0) return c[n][m];
int res;
if(n==0||m==0)res=1; else if(m==1)res=n;
else res=(combination_mod(n-1,m,s+1)+combination_mod(n-1,m-1,s+1))%MOD;
return(c[n][m]=res);
}
int main(){
cin >> N >> M;
N -= N/1000/M*1000*M;
N = N/1000;
cout << combination_mod(M,N) << endl;
}