結果

問題 No.802 だいたい等差数列
コンテスト
ユーザー 梧桐
提出日時 2026-06-20 17:34:08
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 806 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 503 ms
コンパイル使用メモリ 73,088 KB
実行使用メモリ 9,984 KB
最終ジャッジ日時 2026-06-20 17:34:42
合計ジャッジ時間 7,745 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 4
other TLE * 1 -- * 29
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <cstdio>

using namespace std;

typedef long long LL;

const int MOD = 1000000007;

LL ans;
int n, m, d1, d2;

void DFS(int pos, int val) {
    if (pos == n) {
        ans = (ans + 1) % MOD;
        return;
    }
    int ed = min(val + d2, m);
    for (int nxt = val + d1; nxt <= ed; ++nxt) {
        DFS(pos + 1, nxt);
    }
}

/**
 * 暴力分:
 *       20分----D1=D2
 *       4分-----DFS
 */

int main() {
    // freopen("ap.in", "r", stdin);
    // freopen("ap.out", "w", stdout);

    scanf("%d%d%d%d", &n, &m, &d1, &d2);

    if (d1 == d2) {
        LL x = m - 1LL * (n - 1) * d1;
        printf("%lld\n", x < 1 ? 0 : x % MOD);
    } else {
        for (int i = 1; i <= m; ++i) {
            DFS(1, i);
        }
        printf("%lld\n", ans);
    }

    return 0;
}
0