結果

問題 No.1043 直列大学
ユーザー ks2mks2m
提出日時 2020-05-01 22:19:11
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,565 bytes
コンパイル時間 2,012 ms
コンパイル使用メモリ 73,908 KB
実行使用メモリ 63,652 KB
最終ジャッジ日時 2023-08-26 14:47:12
合計ジャッジ時間 11,388 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
54,224 KB
testcase_01 AC 83 ms
53,948 KB
testcase_02 AC 119 ms
56,736 KB
testcase_03 AC 83 ms
53,876 KB
testcase_04 AC 81 ms
53,940 KB
testcase_05 AC 83 ms
53,888 KB
testcase_06 AC 82 ms
53,872 KB
testcase_07 AC 91 ms
54,680 KB
testcase_08 AC 102 ms
54,656 KB
testcase_09 AC 242 ms
60,800 KB
testcase_10 AC 270 ms
63,020 KB
testcase_11 AC 339 ms
62,952 KB
testcase_12 RE -
testcase_13 AC 326 ms
63,064 KB
testcase_14 AC 336 ms
62,964 KB
testcase_15 AC 357 ms
63,084 KB
testcase_16 AC 335 ms
63,652 KB
testcase_17 AC 269 ms
62,928 KB
testcase_18 AC 274 ms
63,108 KB
testcase_19 AC 322 ms
63,048 KB
testcase_20 AC 258 ms
63,356 KB
testcase_21 AC 303 ms
63,096 KB
testcase_22 AC 312 ms
63,100 KB
testcase_23 AC 362 ms
62,976 KB
testcase_24 AC 292 ms
62,984 KB
testcase_25 AC 324 ms
63,008 KB
testcase_26 AC 341 ms
63,080 KB
testcase_27 AC 224 ms
62,284 KB
testcase_28 AC 326 ms
63,076 KB
testcase_29 AC 169 ms
63,020 KB
testcase_30 AC 273 ms
63,068 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(" ");
		int a = Integer.parseInt(sa[0]);
		int 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++) {
			int min = i * a;
			if (min > mx) {
				break;
			}
			int max = Math.min(i * b, mx);
			long cv = dpv[max] - dpv[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