結果

問題 No.1043 直列大学
ユーザー KKT89KKT89
提出日時 2020-05-01 22:12:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 1,393 bytes
コンパイル時間 844 ms
コンパイル使用メモリ 94,820 KB
実行使用メモリ 6,928 KB
最終ジャッジ日時 2023-08-24 05:45:52
合計ジャッジ時間 3,180 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
6,696 KB
testcase_01 AC 7 ms
6,632 KB
testcase_02 AC 9 ms
6,888 KB
testcase_03 AC 7 ms
6,832 KB
testcase_04 AC 7 ms
6,636 KB
testcase_05 AC 7 ms
6,888 KB
testcase_06 AC 7 ms
6,892 KB
testcase_07 AC 9 ms
6,624 KB
testcase_08 AC 9 ms
6,872 KB
testcase_09 AC 37 ms
6,640 KB
testcase_10 AC 44 ms
6,772 KB
testcase_11 AC 64 ms
6,648 KB
testcase_12 AC 69 ms
6,664 KB
testcase_13 AC 58 ms
6,672 KB
testcase_14 AC 61 ms
6,752 KB
testcase_15 AC 67 ms
6,740 KB
testcase_16 AC 60 ms
6,672 KB
testcase_17 AC 46 ms
6,660 KB
testcase_18 AC 45 ms
6,672 KB
testcase_19 AC 57 ms
6,736 KB
testcase_20 AC 45 ms
6,800 KB
testcase_21 AC 53 ms
6,680 KB
testcase_22 AC 55 ms
6,796 KB
testcase_23 AC 68 ms
6,752 KB
testcase_24 AC 50 ms
6,672 KB
testcase_25 AC 58 ms
6,928 KB
testcase_26 AC 61 ms
6,804 KB
testcase_27 AC 33 ms
6,648 KB
testcase_28 AC 57 ms
6,640 KB
testcase_29 AC 22 ms
6,732 KB
testcase_30 AC 44 ms
6,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <math.h>
using namespace std;

typedef long long ll;

constexpr ll mod=1e9+7;

ll dp[2][102100];
ll dp2[2][102101];

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m; cin >> n >> m;
    vector<int> v(n),r(m);
    for(int i=0;i<n;i++){
        cin >> v[i];
    }
    for(int i=0;i<m;i++){
        cin >> r[i];
    }
    int pre=0;
    int nex=1;
    dp[0][0]=1;
    int a,b; cin >> a >> b;
    for(int i=0;i<n;i++){
        for(int j=0;j<=100000;j++){
            (dp[nex][j+v[i]]+=dp[pre][j])%=mod;
            (dp[nex][j]+=dp[pre][j])%=mod;
            dp[pre][j]=0;
        }
        swap(pre,nex);
    }
    int ppre=0;
    int nnex=1;
    dp2[0][0]=1;
    for(int i=0;i<m;i++){
        for(int j=0;j<=100000;j++){
            (dp2[nnex][j+r[i]]+=dp2[ppre][j])%=mod;
            (dp2[nnex][j]+=dp2[ppre][j])%=mod;
            dp2[ppre][j]=0;
        }
        swap(nnex,ppre);
    }
    for(int i=0;i<=100100;i++){
        (dp[pre][i+1]+=dp[pre][i])%=mod;
    }
    ll res=0;
    for(int i=1;i<=100000;i++){
        if(dp2[ppre][i]==0)continue;
        ll aa=min((ll)a*i,100001LL);
        ll bb=min((ll)b*i,100001LL);
        (res+=(dp[pre][bb]-dp[pre][aa-1])%mod*dp2[ppre][i])%=mod;
    }
    if(res<0)res+=mod;
    printf("%lld\n",res);
}
0