結果

問題 No.1043 直列大学
ユーザー akun0716akun0716
提出日時 2020-05-01 22:30:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,274 bytes
コンパイル時間 754 ms
コンパイル使用メモリ 87,092 KB
実行使用メモリ 7,584 KB
最終ジャッジ日時 2023-08-26 15:10:30
合計ジャッジ時間 2,479 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,320 KB
testcase_01 AC 4 ms
7,240 KB
testcase_02 AC 6 ms
7,332 KB
testcase_03 AC 4 ms
7,312 KB
testcase_04 AC 4 ms
7,280 KB
testcase_05 AC 4 ms
7,256 KB
testcase_06 AC 4 ms
7,244 KB
testcase_07 AC 5 ms
7,308 KB
testcase_08 AC 4 ms
7,384 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 13 ms
7,324 KB
testcase_30 AC 23 ms
7,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;



signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, M; cin >> N >> M;
	VI V(N), R(M);
	REP(i, N)cin >> V[i];
	REP(i, M)cin >> R[i];
	int A, B; cin >> A >> B;
	//A--;
	SORT(V);
	SORT(R);

	int dp1[2][100010] = { 0 }, dp2[2][100010] = { 0 };
	dp1[0][0] = dp2[0][0] = 1;

	REP(i, N) {
		REP(j, 100010) {
			dp1[(i + 1) % 2][j] += dp1[i % 2][j];
			if (j + V[i] < 100010) {
				dp1[(i + 1) % 2][j + V[i]] += dp1[i % 2][j];
			}
		}
		REP(j, 100010)dp1[i % 2][j] = 0;
	}
	
	REP(i, 100010) {
		if (dp1[N % 2][i]) {
			//cout << i << " " << dp1[N % 2][i] << endl;
		}
	}


	REP(i, M) {
		REP(j, 100010) {
			dp2[(i + 1) % 2][j] += dp2[i % 2][j];
			if (j + R[i] < 100010) {
				dp2[(i + 1) % 2][j + R[i]] += dp2[i % 2][j];
			}
		}
		REP(j, 100010)dp2[i % 2][j] = 0;;
	}
	
	int ans = 0;
	int cnt[100010] = { 0 };
	cnt[0] = dp1[N % 2][0];
	FOR(i, 1, 100010) {
		cnt[i] = cnt[i - 1] + dp1[N % 2][i];
		cnt[i] %= mod;
	}
	FOR(i, 1, 100010) {
		int ma = B * i, mi = A * i;
		mi--;
		chmin(ma,100005LL);
		chmin(mi,100005LL);
		if (mi == -1) {
			ans += cnt[ma] * dp2[M % 2][i];
		}
		else ans += (cnt[ma] - cnt[mi] + mod)*dp2[M % 2][i];
		
		ans %= mod;
	}



	cout << ans << endl;
	return 0;
}

0