結果

問題 No.1043 直列大学
ユーザー carrot46carrot46
提出日時 2020-05-01 21:50:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 171 ms / 2,000 ms
コード長 3,347 bytes
コンパイル時間 1,558 ms
コンパイル使用メモリ 171,508 KB
実行使用メモリ 161,812 KB
最終ジャッジ日時 2023-08-24 05:41:27
合計ジャッジ時間 5,548 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
8,444 KB
testcase_01 AC 7 ms
6,900 KB
testcase_02 AC 15 ms
13,152 KB
testcase_03 AC 7 ms
7,044 KB
testcase_04 AC 7 ms
6,752 KB
testcase_05 AC 7 ms
6,828 KB
testcase_06 AC 7 ms
6,744 KB
testcase_07 AC 10 ms
9,900 KB
testcase_08 AC 10 ms
9,992 KB
testcase_09 AC 88 ms
83,476 KB
testcase_10 AC 104 ms
99,584 KB
testcase_11 AC 157 ms
148,776 KB
testcase_12 AC 171 ms
161,812 KB
testcase_13 AC 140 ms
135,404 KB
testcase_14 AC 149 ms
142,992 KB
testcase_15 AC 163 ms
156,492 KB
testcase_16 AC 146 ms
140,032 KB
testcase_17 AC 108 ms
103,284 KB
testcase_18 AC 109 ms
103,072 KB
testcase_19 AC 140 ms
132,252 KB
testcase_20 AC 108 ms
101,040 KB
testcase_21 AC 130 ms
121,976 KB
testcase_22 AC 132 ms
127,696 KB
testcase_23 AC 165 ms
160,148 KB
testcase_24 AC 118 ms
113,372 KB
testcase_25 AC 140 ms
133,744 KB
testcase_26 AC 152 ms
143,116 KB
testcase_27 AC 75 ms
71,152 KB
testcase_28 AC 139 ms
132,344 KB
testcase_29 AC 47 ms
44,424 KB
testcase_30 AC 108 ms
100,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;

class mint{
    public:
        ll x;
        static unsigned long long mod;
        static unsigned long long mod_plus;
        mint(){x = 0;}
        mint(ll _x) : x((_x < 0 ? ((_x += mod_plus) < 0 ? _x + mod_plus : _x) : _x)%mod){}
        /*mint& operator=(const ll &a){
            x = a;
            return *this;
        }*/

        mint operator-(){
            return x == 0 ? 0 : mod - x;
        }
        mint& operator+=(const mint& a){
            if((x += a.x) >= mod) x -= mod;
            return *this;
        }
        mint operator+(const mint& a) const{
            mint res(*this);
            return res += a;
        }
        mint& operator-=(const mint& a){
            if((x -= a.x) < 0) x += mod;
            return *this;
        }
        mint operator-(const mint& a) const{
            mint res(*this);
            return res -= a;
        }
        mint& operator*=(const mint& a){
            (x *= a.x)%=mod;
            return *this;
        }
        /*mint& operator*=(const ll& a){
            mint temp(a);
            return *this *= temp;
        }*/
        mint operator*(const mint& a) const{
            mint res(*this);
            return res *= a;
        }
        /*mint operator*(const ll& a) const{
            mint res(*this);
            return res *= a;
        }*/
        mint pow(unsigned long long pw) const{
            mint res(1), comp(*this);
            while(pw){
                if(pw&1) res *= comp;
                comp *= comp;
                pw >>= 1;
            }
            return res;
        }
        //以下、modが素数のときのみ
        mint inv() const{
            mint res(*this);
            return res.pow(mod - 2);
        }
        mint& operator/=(const mint &a){
            (x *= a.inv().x)%=mod;
            return *this;
        }
        mint operator/(const mint &a) const{
            mint res(*this);
            return res /= a;
        }
};
ostream& operator<<(ostream& os, const mint& a){
    os << a.x;
    return os;
}
unsigned long long mint::mod = int(1e+9) + 7;
unsigned long long mint::mod_plus = (LLONG_MAX / mint::mod) * mint::mod;
typedef vector<mint> vm;

void npsk(ll n, vector<vm> &dp, vec &a){
    dp[0][0] = 1;
    rep(i,n){
        rep(j, int(1e+5) + 1){
            dp[i+1][j] += dp[i][j];
            if(j + a[i] <= int(1e+5)) dp[i+1][j + a[i]] += dp[i][j];
        }
    }
}
int main() {
    cin>>N>>M;
    vec v(N), r(M);
    rep(i,N) cin>>v[i];
    rep(i,M) cin>>r[i];
    cin>>A>>B;
    vector<vm> dpv(N + 1, vm(int(1e+5) + 1)), dpr(M + 1, vm(int(1e+5) + 1));
    npsk(N, dpv, v);
    npsk(M, dpr, r);
    rep(j,int(1e+5)) dpv[N][j+1] += dpv[N][j];
    vm &sum = dpv[N];
    mint ans(0);
    reps(i,1,int(1e+5) + 1){
        ans += dpr[M][i] * (sum[min(ll(i) * B, ll(1e+5))] - sum[min(ll(i) * A - 1, ll(1e+5))]);
    }
    cout<<ans<<endl;
}
0