結果

問題 No.1043 直列大学
ユーザー misora192misora192
提出日時 2020-06-02 08:54:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,357 bytes
コンパイル時間 2,033 ms
コンパイル使用メモリ 170,708 KB
実行使用メモリ 7,296 KB
最終ジャッジ日時 2024-05-02 22:58:37
合計ジャッジ時間 4,132 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
7,168 KB
testcase_01 AC 8 ms
7,040 KB
testcase_02 AC 12 ms
7,040 KB
testcase_03 AC 9 ms
7,168 KB
testcase_04 AC 8 ms
7,040 KB
testcase_05 AC 9 ms
7,040 KB
testcase_06 AC 8 ms
7,040 KB
testcase_07 AC 11 ms
7,040 KB
testcase_08 AC 10 ms
7,040 KB
testcase_09 AC 43 ms
7,040 KB
testcase_10 WA -
testcase_11 AC 70 ms
7,168 KB
testcase_12 AC 76 ms
7,168 KB
testcase_13 WA -
testcase_14 AC 62 ms
7,040 KB
testcase_15 AC 75 ms
7,168 KB
testcase_16 AC 66 ms
7,168 KB
testcase_17 AC 47 ms
7,168 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 78 ms
7,040 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 26 ms
7,168 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

ll ceil(ll a, ll b){
	return (a + b - 1) / b;
}

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

	ll MOD = 1e9 + 7;

	ll n, m;
	cin >> n >> m;

	vector<ll> v(n), r(m);
	rep(i, n) cin >> v[i];
	rep(i, m) cin >> r[i];

	ll a, b;
	cin >> a >> b;

	int max_n = 101010;

	ll dpv[2][max_n];
	rep(i, 2) rep(j, max_n) dpv[i][j] = 0;
	dpv[0][0] = 1;

	rep(i, n) {
		rep(j, max_n) dpv[(i+1)%2][j] = 0;
		rep(j, max_n){
			dpv[(i+1)%2][j] += dpv[i%2][j];
			dpv[(i+1)%2][j] %= MOD;
			if(j + v[i] < max_n){
				dpv[(i+1)%2][j+v[i]] += dpv[i%2][j];
				dpv[(i+1)%2][j+v[i]] %= MOD;
			}
		} 
	}

	ll dpr[2][max_n];
	rep(i, 2) rep(j, max_n) dpr[i][j] = 0;
	dpr[0][0] = 1;

	rep(i, n) {
		rep(j, max_n) dpr[(i+1)%2][j] = 0;
		rep(j, max_n){
			dpr[(i+1)%2][j] += dpr[i%2][j];
			dpr[(i+1)%2][j] %= MOD;
			if(j + r[i] < max_n){
				dpr[(i+1)%2][j+r[i]] += dpr[i%2][j];
				dpr[(i+1)%2][j+r[i]] %= MOD;
			} 
		}
	}

	vector<ll> sr(max_n+1, 0);
	sr[1] = dpr[m%2][1];
	for(int i = 1; i < max_n; i++) {
		sr[i+1] = sr[i] + dpr[m%2][i+1];
		sr[i+1] %= MOD;
	}

	ll ans = 0;
	for(int i = 1; i < max_n; i++){
		ll num = sr[i / a] + MOD - sr[max(ceil((ll)i, b) - 1, 0ll)];
		num %= MOD;
		ans += dpv[n%2][i] * num;
		ans %= MOD;
	}

	cout << ans << endl;
}
0