結果

問題 No.1043 直列大学
ユーザー motmot
提出日時 2020-05-01 22:26:27
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 2,137 bytes
コンパイル時間 1,018 ms
コンパイル使用メモリ 79,172 KB
実行使用メモリ 160,652 KB
最終ジャッジ日時 2023-08-24 05:48:56
合計ジャッジ時間 3,172 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,160 KB
testcase_01 AC 3 ms
5,448 KB
testcase_02 AC 7 ms
10,804 KB
testcase_03 AC 4 ms
5,444 KB
testcase_04 AC 3 ms
5,408 KB
testcase_05 AC 3 ms
5,436 KB
testcase_06 AC 3 ms
5,384 KB
testcase_07 AC 7 ms
10,860 KB
testcase_08 AC 6 ms
10,764 KB
testcase_09 AC 47 ms
84,504 KB
testcase_10 AC 55 ms
98,796 KB
testcase_11 AC 80 ms
147,992 KB
testcase_12 AC 87 ms
160,652 KB
testcase_13 AC 71 ms
133,728 KB
testcase_14 AC 77 ms
141,852 KB
testcase_15 AC 84 ms
156,236 KB
testcase_16 AC 75 ms
139,960 KB
testcase_17 AC 56 ms
102,904 KB
testcase_18 AC 55 ms
102,960 KB
testcase_19 AC 69 ms
131,624 KB
testcase_20 AC 55 ms
100,928 KB
testcase_21 AC 64 ms
121,336 KB
testcase_22 AC 67 ms
127,548 KB
testcase_23 AC 85 ms
158,340 KB
testcase_24 AC 59 ms
113,212 KB
testcase_25 AC 71 ms
131,560 KB
testcase_26 AC 75 ms
141,876 KB
testcase_27 AC 40 ms
70,204 KB
testcase_28 AC 73 ms
131,608 KB
testcase_29 AC 24 ms
43,544 KB
testcase_30 AC 51 ms
101,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
const int inf=1e9+7;
const ll mod=1e9+7;

ll VDP[105][100005];
ll RDP[105][100005];

int main() {
    int N, M;
    cin>>N>>M;
    vector<ll> 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 A, B;
    cin>>A>>B;
    VDP[0][V[0]] = 1;
    RDP[0][R[0]] = 1;
    for(int i=1;i<N;++i){
        for(int j=1;j<=100000;++j){
            if(V[i]<=j){
                if(V[i]==j){
                    VDP[i][j] = VDP[i-1][j] + 1;
                }
                else{
                    VDP[i][j] = VDP[i-1][j] + VDP[i-1][j-V[i]];
                }
            }
            else{
                VDP[i][j] = VDP[i-1][j];
            }
            VDP[i][j] %= mod;
        }
    }
    for(int i=1;i<M;++i){
        for(int j=1;j<=100000;++j){
            if(R[i]<=j){
                if(R[i]==j){
                    RDP[i][j] = RDP[i-1][j] + 1;
                }
                else{
                    RDP[i][j] = RDP[i-1][j] + RDP[i-1][j-R[i]];
                }
            }
            else{
                RDP[i][j] = RDP[i-1][j];
            }
            RDP[i][j] %= mod;
        }
    }
    for(int i=1;i<100003;++i){
        VDP[N-1][i] += VDP[N-1][i-1];
        VDP[N-1][i] %= mod;
        //RDP[i] += RDP[i-1];
    }
    /**
    for(int i=0;i<N;++i){
        for(int j=0;j<100;++j){
            cout<<VDP[i][j]<<" ";
        }
        cout<<endl;
    }
    cout<<endl;
    **/
    ll ans = 0;
    for(ll i=1;i<=100000;++i){
        if(i*A>100000) break;
        if(i*B>100000){
            ans += ((VDP[N-1][100000] - VDP[N-1][i*A-1]) * RDP[M-1][i]) % mod;
            ans %= mod;
        }
        else{
            ans += ((VDP[N-1][i*B] - VDP[N-1][i*A-1]) * RDP[M-1][i]) % mod;
            ans %= mod;
        }
    }
    if(ans<0) cout<<ans + mod<<endl;
    else cout<<ans<<endl;
}
0