結果

問題 No.1043 直列大学
ユーザー hokto
提出日時 2020-05-02 17:15:14
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,132 bytes
コンパイル時間 2,749 ms
コンパイル使用メモリ 202,196 KB
最終ジャッジ日時 2025-01-10 05:59:19
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

#define rep(i,n) for(ll i=0;i<n;i++)
#define MOD 1000000007
#define MAX_VR 1000
#define ll long long int
using namespace std;
int main()
{
	ll N,M;
	cin>>N>>M;
	vector<ll> V(N);
	vector<ll> R(M);
	sort(V.begin(),V.end());
	sort(R.begin(),R.end());
	rep(i,N) cin>>V[i];
	rep(i,M) cin>>R[i];
	ll A,B;
	cin>>A>>B;
	vector<vector<ll>> dp_v(N+1,vector<ll>(N*MAX_VR+1,0));
	vector<vector<ll>> dp_r(M+1,vector<ll>(M*MAX_VR+1,0));
	dp_v[0][0]=1;
	dp_r[0][0]=1;
	rep(i,N)
	{
		for(ll j=N*MAX_VR-V[i];j>=0;j--)
		{
			dp_v[i+1][j]+=dp_v[i][j];
			dp_v[i+1][j]%=MOD;
			dp_v[i+1][j+V[i]]+=dp_v[i][j];
			dp_v[i+1][j+V[i]]%=MOD;
		}
	}

	rep(i,M)
	{
		for(ll j=M*MAX_VR-R[i];j>=0;j--)
		{
			dp_r[i+1][j]+=dp_r[i][j];
			dp_r[i+1][j]%=MOD;
			dp_r[i+1][j+R[i]]+=dp_r[i][j];
			dp_r[i+1][j+R[i]]%=MOD;
		}
	}

	vector<ll> alloc(N*MAX_VR+2,0);
	rep(i,N*MAX_VR+1)
	{
		alloc[i+1]=alloc[i]+dp_v[N][i];
	}
	ll ans=0;
	for(ll i=1;i<=M*MAX_VR;i++)
	{
		ll max=B*i;
		ll min=A*i;
		if(min>N*MAX_VR)break;
		if(max>N*MAX_VR)max=N*MAX_VR;
		ans+=(alloc[max+1]-alloc[min])*dp_r[M][i];
		ans%=MOD;
	}
	cout<<ans<<endl;
	return 0;
}
0