結果

問題 No.1043 直列大学
ユーザー ks2mks2m
提出日時 2020-05-01 22:22:30
言語 Java21
(openjdk 21)
結果
AC  
実行時間 381 ms / 2,000 ms
コード長 1,581 bytes
コンパイル時間 3,079 ms
コンパイル使用メモリ 74,428 KB
実行使用メモリ 63,196 KB
最終ジャッジ日時 2023-08-24 05:48:21
合計ジャッジ時間 11,635 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
53,956 KB
testcase_01 AC 86 ms
54,232 KB
testcase_02 AC 120 ms
56,632 KB
testcase_03 AC 88 ms
53,616 KB
testcase_04 AC 89 ms
54,024 KB
testcase_05 AC 78 ms
53,684 KB
testcase_06 AC 88 ms
53,884 KB
testcase_07 AC 108 ms
54,252 KB
testcase_08 AC 99 ms
54,956 KB
testcase_09 AC 251 ms
63,196 KB
testcase_10 AC 280 ms
62,616 KB
testcase_11 AC 348 ms
62,604 KB
testcase_12 AC 381 ms
62,904 KB
testcase_13 AC 334 ms
63,024 KB
testcase_14 AC 343 ms
62,768 KB
testcase_15 AC 362 ms
62,884 KB
testcase_16 AC 336 ms
63,108 KB
testcase_17 AC 275 ms
62,716 KB
testcase_18 AC 285 ms
62,772 KB
testcase_19 AC 320 ms
62,708 KB
testcase_20 AC 271 ms
63,044 KB
testcase_21 AC 319 ms
62,792 KB
testcase_22 AC 321 ms
62,704 KB
testcase_23 AC 375 ms
62,640 KB
testcase_24 AC 302 ms
62,720 KB
testcase_25 AC 328 ms
62,860 KB
testcase_26 AC 347 ms
62,792 KB
testcase_27 AC 221 ms
62,156 KB
testcase_28 AC 327 ms
62,700 KB
testcase_29 AC 186 ms
62,544 KB
testcase_30 AC 276 ms
63,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int m = Integer.parseInt(sa[1]);

		sa = br.readLine().split(" ");
		int[] v = new int[n];
		for (int i = 0; i < n; i++) {
			v[i] = Integer.parseInt(sa[i]);
		}

		sa = br.readLine().split(" ");
		int[] r = new int[m];
		for (int i = 0; i < m; i++) {
			r[i] = Integer.parseInt(sa[i]);
		}

		sa = br.readLine().split(" ");
		long a = Integer.parseInt(sa[0]);
		long b = Integer.parseInt(sa[1]);
		br.close();

		int mod = 1000000007;
		int mx = 100000;
		long[] dpv = dp(v, n);
		for (int i = 1; i <= mx; i++) {
			dpv[i] += dpv[i - 1];
			dpv[i] %= mod;
		}
		long[] dpr = dp(r, m);

		long ans = 0;
		for (int i = 1; i <= mx; i++) {
			long min = i * a;
			if (min > mx) {
				break;
			}
			long max = Math.min(i * b, mx);
			long cv = dpv[(int) max] - dpv[(int) min - 1] + mod;
			ans += cv * dpr[i];
			ans %= mod;
		}
		System.out.println(ans);
	}

	static long[] dp(int[] v, int n) {
		int mod = 1000000007;
		int mx = 100000;
		long[] dp = new long[mx + 1];
		dp[0] = 1;
		for (int i = 0; i < n; i++) {
			long[] work = new long[mx + 1];
			for (int j = mx - v[i] + 1; j <= mx; j++) {
				work[j] = dp[j];
			}
			for (int j = mx - v[i]; j >= 0; j--) {
				work[j + v[i]] += dp[j];
				work[j + v[i]] %= mod;
				work[j] = dp[j];
			}
			dp = work;
		}
		return dp;
	}
}
0