結果

問題 No.1043 直列大学
ユーザー ikdikd
提出日時 2020-05-01 23:08:37
言語 Nim
(2.0.2)
結果
RE  
実行時間 -
コード長 1,179 bytes
コンパイル時間 3,926 ms
コンパイル使用メモリ 69,120 KB
実行使用メモリ 5,200 KB
最終ジャッジ日時 2023-08-26 15:44:38
合計ジャッジ時間 5,376 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 4 ms
4,376 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 112 ms
5,200 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 AC 60 ms
4,380 KB
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
権限があれば一括ダウンロードができます

ソースコード

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(n, 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