結果

問題 No.1043 直列大学
ユーザー akun0716akun0716
提出日時 2020-05-01 23:03:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 2,209 bytes
コンパイル時間 844 ms
コンパイル使用メモリ 86,872 KB
実行使用メモリ 7,500 KB
最終ジャッジ日時 2023-08-24 05:51:52
合計ジャッジ時間 3,065 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,208 KB
testcase_01 AC 5 ms
7,352 KB
testcase_02 AC 8 ms
7,344 KB
testcase_03 AC 5 ms
7,296 KB
testcase_04 AC 5 ms
7,292 KB
testcase_05 AC 5 ms
7,388 KB
testcase_06 AC 5 ms
7,224 KB
testcase_07 AC 6 ms
7,352 KB
testcase_08 AC 6 ms
7,224 KB
testcase_09 AC 34 ms
7,224 KB
testcase_10 AC 40 ms
7,296 KB
testcase_11 AC 59 ms
7,356 KB
testcase_12 AC 65 ms
7,300 KB
testcase_13 AC 53 ms
7,492 KB
testcase_14 AC 58 ms
7,356 KB
testcase_15 AC 64 ms
7,300 KB
testcase_16 AC 56 ms
7,220 KB
testcase_17 AC 42 ms
7,352 KB
testcase_18 AC 42 ms
7,360 KB
testcase_19 AC 52 ms
7,216 KB
testcase_20 AC 41 ms
7,284 KB
testcase_21 AC 48 ms
7,232 KB
testcase_22 AC 50 ms
7,388 KB
testcase_23 AC 63 ms
7,300 KB
testcase_24 AC 46 ms
7,300 KB
testcase_25 AC 53 ms
7,500 KB
testcase_26 AC 57 ms
7,364 KB
testcase_27 AC 30 ms
7,352 KB
testcase_28 AC 53 ms
7,216 KB
testcase_29 AC 19 ms
7,292 KB
testcase_30 AC 40 ms
7,224 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;
	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;
			dp1[(i + 1) % 2][j] %= mod;
		}
	}

	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;
			dp2[(i + 1) % 2][j] %= mod;
		}
	}


	int ans = 0;
	int cnt[100010] = { 0 };
	
	FOR(i, 1, 100010) {
		cnt[i] = cnt[i - 1] + dp1[N % 2][i];
		cnt[i] %= mod;
	}

	eFOR(i, 1, 100000) {
		int ma = B * i, mi = A * i;
		mi--;
		if (mi >= 100000) {
			continue;
		}
		chmin(ma, 100000LL);
		chmin(mi, 100000LL);
		
		
		ans += (cnt[ma] - cnt[mi] + mod)*dp2[M % 2][i];

		ans %= mod;
	}

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

0