結果

問題 No.129 お年玉(2)
ユーザー koyumeishikoyumeishi
提出日時 2015-01-17 00:39:37
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 54 ms / 5,000 ms
コード長 849 bytes
コンパイル時間 717 ms
コンパイル使用メモリ 78,536 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-27 23:00:59
合計ジャッジ時間 2,830 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
using namespace std;

#define MOD 1000000000

int main(){
	long long n,m;
	cin >> n >> m;
	n -= ((n/m)/1000) * 1000 * m;

	n /= 1000;

	cerr << n << " " << m << endl;

	vector<vector<long long>> dp(2, vector<long long>(n+1, 0));
	dp[0][0] = 1;
	for(int i=0; i<m; ++i){
		int pos = i%2;
		int next = (i+1)%2;

		fill(dp[next].begin(), dp[next].end(), 0);
		
		for(int j=max(0LL, n-(m-i)); j<=i+1 && j<=n; ++j){
			
			dp[next][j] += dp[pos][j];
			if(dp[next][j]>=MOD) dp[next][j] -= MOD;

			if(j+1<=n){
				dp[next][j+1] += dp[pos][j];
				if(dp[next][j+1]>=MOD) dp[next][j+1] -= MOD;
			}
		}
		
	}

	long long ans = dp[m%2][n] % MOD;
	cout << ans << endl;
	return 0;
}
0