結果

問題 No.1043 直列大学
ユーザー joybeeeejoybeeee
提出日時 2020-05-13 20:19:15
言語 Java21
(openjdk 21)
結果
AC  
実行時間 447 ms / 2,000 ms
コード長 1,422 bytes
コンパイル時間 2,109 ms
コンパイル使用メモリ 73,720 KB
実行使用メモリ 59,188 KB
最終ジャッジ日時 2023-08-24 12:48:59
合計ジャッジ時間 13,020 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 157 ms
58,200 KB
testcase_01 AC 149 ms
58,128 KB
testcase_02 AC 202 ms
59,188 KB
testcase_03 AC 152 ms
57,784 KB
testcase_04 AC 154 ms
57,624 KB
testcase_05 AC 152 ms
57,896 KB
testcase_06 AC 151 ms
57,848 KB
testcase_07 AC 165 ms
58,320 KB
testcase_08 AC 161 ms
58,080 KB
testcase_09 AC 320 ms
58,892 KB
testcase_10 AC 329 ms
58,832 KB
testcase_11 AC 418 ms
58,320 KB
testcase_12 AC 447 ms
58,436 KB
testcase_13 AC 393 ms
57,928 KB
testcase_14 AC 394 ms
58,244 KB
testcase_15 AC 421 ms
58,216 KB
testcase_16 AC 393 ms
57,968 KB
testcase_17 AC 333 ms
58,340 KB
testcase_18 AC 345 ms
58,388 KB
testcase_19 AC 389 ms
58,236 KB
testcase_20 AC 328 ms
58,400 KB
testcase_21 AC 372 ms
58,520 KB
testcase_22 AC 383 ms
58,216 KB
testcase_23 AC 440 ms
57,928 KB
testcase_24 AC 358 ms
58,140 KB
testcase_25 AC 392 ms
58,284 KB
testcase_26 AC 411 ms
58,124 KB
testcase_27 AC 278 ms
58,484 KB
testcase_28 AC 392 ms
58,484 KB
testcase_29 AC 230 ms
58,412 KB
testcase_30 AC 333 ms
58,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int mod = 1000000007;
      int n = sc.nextInt();
      int m = sc.nextInt();
      int[] vArr = new int[n];
      int[] rArr = new int[m];

      for(int i = 0; i < n; i++)
        vArr[i] = sc.nextInt();
      for(int i = 0; i < m; i++)
        rArr[i] = sc.nextInt();

      long a = sc.nextInt();
      long b = sc.nextInt();
      
      long[] dpV = new long[101010]; dpV[0] = 1L;
      long[] dpR = new long[101010]; dpR[0] = 1L;

      for(int i = 0; i < n; i++)
        for(int j = dpV.length - 1; j > 0; j--) {
          if(j - vArr[i] < 0) continue;
          dpV[j] = (dpV[j] + dpV[j - vArr[i]]) % mod;
        }

      for(int i = 0; i < m; i++)
        for(int j = dpR.length - 1; j > 0; j--) {
          if(j - rArr[i] < 0) continue;
          dpR[j] = (dpR[j] + dpR[j - rArr[i]]) % mod;
        }

      for(int i = 1; i < dpV.length; i++)
        dpV[i] = (dpV[i] + dpV[i-1]);

      long cnt = 0L;
      for(int r = 1; r < dpR.length; r++) {
        if(dpR[r] == 0) continue;
        long leftV = a * r;
        long rightV = b * r;
        if(leftV > dpV.length - 1) continue;
        rightV = Math.min(rightV, dpV.length - 1);
        cnt = cnt + (long)dpR[r] * ((dpV[(int)rightV] - dpV[(int)leftV - 1]) % mod) % mod;
      }
      System.out.println(cnt % mod);
  }
}
0