結果

問題 No.269 見栄っ張りの募金活動
コンテスト
ユーザー 小畑裕貴
提出日時 2026-01-31 15:42:30
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
結果
AC  
実行時間 18 ms / 5,000 ms
コード長 803 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 976 ms
コンパイル使用メモリ 135,236 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2026-01-31 15:42:33
合計ジャッジ時間 2,165 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <algorithm>
#include <array>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int MOD = 1e9+7;


int main() {
    int n, s, k;
    cin >> n >> s >> k;
    for (int i = 0; i < n; i++) {
        s -= i*k;
    }
    if (s < 0) cout << 0 << endl;
    else {
        vector<vector<int>> dp(n+1, vector<int>(s+1, 0));
        dp[0][0] = 1;
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j <= s; j++) {
                if (j - i >= 0) dp[i][j] = (dp[i][j] + dp[i][j-i]) % MOD;
                if (i - 1 >= 0) dp[i][j] = (dp[i][j] + dp[i-1][j]) % MOD;
            }
        }
        cout << dp[n][s] << endl;
    }
}
0