結果

問題 No.269 見栄っ張りの募金活動
ユーザー koyumeishikoyumeishi
提出日時 2015-08-21 23:14:50
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 11 ms / 5,000 ms
コード長 1,071 bytes
コンパイル時間 569 ms
コンパイル使用メモリ 77,352 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-23 01:04:43
合計ジャッジ時間 1,691 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 5 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 11 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 5 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 4 ms
4,376 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 4 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 8 ms
4,376 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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 1000000007

ostream& operator << (ostream& os, vector<long long>& v){
	for(int i=0; i<v.size(); i++){
		os << v[i] << " ";
	}
	return os;
}

int main(){
	long long n,s,k;
	cin >> n >> s >> k;

	vector<long long> dp(s+1, 0);
	for(int i=0; i<=s; i++){
		if(s < i*n) break;
		dp[s - i*n] = 1;
	}
	
	//cerr << dp << endl;

	for(int i=1; i<n; i++){
		vector<long long> dp_(s+1, 0);
		for(int j=0; j<=s; j++){
			if(j - k*(n-i) < 0) continue;
			long long& v =  dp_[ j-k*(n-i) ];
			v += dp[j];
			if( v >= MOD ) v-=MOD;
		}
		vector<bool> visit(s+1, false);
		for(int j=s; j>=0; j--){
			int pos = j;
			while(pos >= 0 && visit[pos] == false){
				visit[pos] = true;
				if( pos - (n-i) < 0) continue;
				
				dp_[pos - (n-i)] += dp_[pos];
				if(dp_[pos - (n-i)] >= MOD) dp_[pos - (n-i)] -= MOD;
			}
		}
		swap(dp, dp_);
	}

	cout << dp[0] << endl;

	return 0;
}
0