結果

問題 No.802 だいたい等差数列
ユーザー nejinejinejineji
提出日時 2020-03-08 15:17:25
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 540 ms / 2,000 ms
コード長 2,163 bytes
コンパイル時間 1,721 ms
コンパイル使用メモリ 167,152 KB
実行使用メモリ 50,176 KB
最終ジャッジ日時 2024-04-24 21:07:39
合計ジャッジ時間 21,305 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 503 ms
34,560 KB
testcase_01 AC 501 ms
34,688 KB
testcase_02 AC 503 ms
34,688 KB
testcase_03 AC 503 ms
34,560 KB
testcase_04 AC 500 ms
34,432 KB
testcase_05 AC 501 ms
34,560 KB
testcase_06 AC 503 ms
34,560 KB
testcase_07 AC 503 ms
34,560 KB
testcase_08 AC 501 ms
34,560 KB
testcase_09 AC 502 ms
34,432 KB
testcase_10 AC 533 ms
48,640 KB
testcase_11 AC 534 ms
49,920 KB
testcase_12 AC 528 ms
48,128 KB
testcase_13 AC 533 ms
50,176 KB
testcase_14 AC 528 ms
48,768 KB
testcase_15 AC 535 ms
50,176 KB
testcase_16 AC 530 ms
49,152 KB
testcase_17 AC 503 ms
34,432 KB
testcase_18 AC 501 ms
34,432 KB
testcase_19 AC 533 ms
50,176 KB
testcase_20 AC 536 ms
50,048 KB
testcase_21 AC 536 ms
50,048 KB
testcase_22 AC 535 ms
50,176 KB
testcase_23 AC 532 ms
50,176 KB
testcase_24 AC 502 ms
34,432 KB
testcase_25 AC 532 ms
50,176 KB
testcase_26 AC 503 ms
34,560 KB
testcase_27 AC 530 ms
50,176 KB
testcase_28 AC 512 ms
39,168 KB
testcase_29 AC 540 ms
50,176 KB
testcase_30 AC 501 ms
34,560 KB
testcase_31 AC 515 ms
34,560 KB
testcase_32 AC 502 ms
34,432 KB
testcase_33 AC 521 ms
43,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i, x, y) for (ll i = x; i <= y; i++)
#define BIT(t) (1ll << t)
#define PER(i, y, x) for (ll i = y; i >= x; i--)
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define pll pair<ll, ll>
#define SIZE(v) ll(v.size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
//        ios::sync_with_stdio(false);
//        cin.tie(nullptr);

ll const MOD = 1e9 + 7;
ll mod_p(ll x, ll y) {
       x %= MOD;
       y %= MOD;
       return (x + y + MOD) % MOD;
}

ll mod_m(ll x, ll y) {
       x %= MOD;
       y %= MOD;
       return x * y%MOD;
}

ll mod_pow(ll x, ll t) {
       x %= MOD;
       if (t == 0) {
               return 1;
       }
       else {
               ll v = mod_pow(x, t / 2);
               if (t % 2 == 0) {
                       return v * v % MOD;
               }
               else {
                       return v * v%MOD * x %MOD;
               }
       }
}

ll mod_inv(ll x) {
       return mod_pow(x, MOD - 2);
}

vll fct(2e6+1), invfct(2e6+1);
void init(){
        fct[0] = invfct[0] = 1;
        REP(i,1,2e6){
                fct[i] = mod_m(fct[i-1] , i);
                invfct[i] = mod_inv(fct[i]);
        }
}

ll ncr(ll n, ll r){
        return mod_m(fct[n], mod_m(invfct[r], invfct[n-r]));
}

int main(){
        init();
        ll n,m,d1, d2;
        cin >> n >> m >> d1 >> d2;
        ll d = d2 - d1;
        ll l = m - 1 - d1*(n-1);
        if(l < 0){
                cout << 0 << endl;
                return 0;
        }
        vll a(m+2), sm(m+2,0);
        REP(i,0,m){
                a[i] = ncr(n+i-1, i);
        }
        sm[0] = a[0];
        REP(i,1,m){
                sm[i] = mod_p(sm[i-1],a[i]);
        }
        ll ans = 0;
        REP(i,0,n-1){
                ll  tmp = ncr(n-1, i);
                if(i % 2 == 1){
                        tmp = mod_m(tmp, -1);
                }
                ll v = l - i * (d + 1);
                if(v < 0) break;
                ans = mod_p(ans, mod_m(sm[v], tmp));
               // cout << v << " " << mod_m(sm[v], tmp) << endl;
        }
        cout << ans << endl;
}
0