結果

問題 No.1043 直列大学
ユーザー KKT89
提出日時 2020-05-01 22:12:58
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 1,393 bytes
コンパイル時間 1,061 ms
コンパイル使用メモリ 94,584 KB
最終ジャッジ日時 2025-01-10 04:59:20
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

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);
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0