結果

問題 No.1201 お菓子配り-4
ユーザー 👑 obakyanobakyan
提出日時 2021-07-28 13:07:04
言語 Lua
(LuaJit 2.1.1696795921)
結果
TLE  
実行時間 -
コード長 813 bytes
コンパイル時間 164 ms
コンパイル使用メモリ 5,332 KB
実行使用メモリ 7,060 KB
最終ジャッジ日時 2023-10-11 10:09:16
合計ジャッジ時間 9,829 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 250 ms
7,060 KB
testcase_01 AC 3,406 ms
4,352 KB
testcase_02 TLE -
testcase_03 AC 2,428 ms
4,352 KB
testcase_04 AC 1,156 ms
4,348 KB
testcase_05 AC 2,877 ms
4,352 KB
testcase_06 AC 438 ms
4,348 KB
testcase_07 AC 2,360 ms
4,348 KB
testcase_08 AC 3,626 ms
4,356 KB
testcase_09 AC 3,253 ms
4,352 KB
testcase_10 AC 43 ms
4,356 KB
testcase_11 AC 1,405 ms
4,352 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

local function floorSum(n, m, a, b)
  local ans = 0LL
  while true do
    if m <= a then
      local v = a / m
      ans = ans + v * n * (n - 1LL) / 2LL
      a = a % m
    end
    if m <= b then
      ans = ans + (b / m) * n
      b = b % m
    end
    if a == 0LL then break end
    local y = (a * n + b) / m
    local z = (a * n + b) % m
    n, m, a, b = y, a, m, z
  end
  return ans
end

local n, m = io.read("*n", "*n")
local a, b = {}, {}
for i = 1, n do
  a[i] = io.read("*n") * 1LL
end
for i = 1, m do
  b[i] = io.read("*n") * 1LL
end
local mod = 1000000007LL
local ret = 0LL
for i = 1, n do
  for j = 1, m do
    local v = floorSum(b[j] + 1, b[j], a[i], 0LL)
    v = v % mod
    ret = (ret + v) % mod
  end
end
ret = (ret + ret) % mod
ret = tostring(ret):gsub("LL", "")
print(ret)

-- print(os.clock())
0