結果

問題 No.1043 直列大学
ユーザー ikdikd
提出日時 2020-05-01 23:10:10
言語 Nim
(2.0.0)
結果
AC  
実行時間 131 ms / 2,000 ms
コード長 1,179 bytes
コンパイル時間 3,113 ms
コンパイル使用メモリ 69,172 KB
実行使用メモリ 5,136 KB
最終ジャッジ日時 2023-08-24 12:33:39
合計ジャッジ時間 5,285 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 4 ms
4,380 KB
testcase_10 AC 8 ms
4,376 KB
testcase_11 AC 46 ms
4,380 KB
testcase_12 AC 131 ms
5,136 KB
testcase_13 AC 53 ms
4,380 KB
testcase_14 AC 58 ms
4,376 KB
testcase_15 AC 67 ms
4,376 KB
testcase_16 AC 56 ms
4,380 KB
testcase_17 AC 32 ms
4,376 KB
testcase_18 AC 28 ms
4,376 KB
testcase_19 AC 52 ms
4,376 KB
testcase_20 AC 28 ms
4,380 KB
testcase_21 AC 46 ms
4,380 KB
testcase_22 AC 47 ms
4,376 KB
testcase_23 AC 70 ms
4,380 KB
testcase_24 AC 35 ms
4,380 KB
testcase_25 AC 51 ms
4,380 KB
testcase_26 AC 55 ms
4,376 KB
testcase_27 AC 20 ms
4,376 KB
testcase_28 AC 31 ms
4,376 KB
testcase_29 AC 4 ms
4,376 KB
testcase_30 AC 47 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import strutils, sequtils, math

let read = iterator: string {.closure.} =
  while true:
    for s in stdin.readLine.split:
      yield s

proc main() =
  let n, m = read().parseInt
  var
    v = newSeqWith(n, read().parseInt)
    r = newSeqWith(m, read().parseInt)
  let A, B = read().parseInt

  const mo: int64 = 1000000007
  let
    vsum = v.sum
    rsum = r.sum
  var
    dp = newSeq[int64](vsum + 1)
    ep = newSeq[int64](rsum + 1)
  dp[0] = 1
  for i in 0..<n:
    for s in countdown(vsum, 0):
      if s + v[i] <= vsum:
        dp[s + v[i]] = (dp[s + v[i]] + dp[s]) mod mo
  ep[0] = 1
  for i in 0..<m:
    for s in countdown(rsum, 0):
      if s + r[i] <= rsum:
        ep[s + r[i]] = (ep[s + r[i]] + ep[s]) mod mo
  var c = newSeq[int64](ep.len + 1)
  for i in 1..ep.len:
    c[i] = c[i - 1]
    if i < ep.len:
      c[i] = (c[i] + ep[i]) mod mo
  # echo ep
  # echo c
  var ans: int64 = 0
  for s in 1..vsum:
    if dp[s] == 0:
      continue
    var
      i = (s + B - 1) div B
      j = min(rsum, s div A)
    if i <= j:
      # echo s, " ", i, " ", j
      let w = (c[j] - c[max(0, i - 1)] + mo) mod mo
      ans = (ans + dp[s] * w mod mo) mod mo
  echo ans
main()
0