結果

問題 No.1201 お菓子配り-4
ユーザー 👑 obakyanobakyan
提出日時 2021-07-29 22:01:21
言語 Lua
(LuaJit 2.1.1696795921)
結果
WA  
実行時間 -
コード長 1,239 bytes
コンパイル時間 97 ms
コンパイル使用メモリ 5,156 KB
実行使用メモリ 8,712 KB
最終ジャッジ日時 2023-10-12 20:04:54
合計ジャッジ時間 51,077 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

local mfl, mce = math.floor, math.ceil
local mod = 1000000007
local half = 500000004
local function bmul(x, y)
  local x1, y1 = mfl(x / 31623), mfl(y / 31623)
  local x0, y0 = x - x1 * 31623, y - y1 * 31623
  return (x1 * y1 * 14122 + (x1 * y0 + x0 * y1) * 31623 + x0 * y0) % mod
end
local function badd(x, y) return (x + y) % mod end
local ret = 0
local function floorSum(n, m, a, b)
  local f = f
  while true do
    if m <= a then
      local v = mfl(a / m)
      ret = badd(ret, bmul(v, bmul(n, bmul(n - 1, half))))
      a = a % m
    end
    if m <= b then
      ret = badd(ret, bmul(n, mfl(b / m)))
      b = b % m
    end
    if a == 0 then break end
    if f then
      n, m, a, b = a + mfl(a / m), a, m, a % m
      f = false
    else
      local y = mfl((a * n + b) / m)
      local z = (a * n + b) % m
      n, m, a, b = y, a, m, z
    end
  end
end

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

-- print(os.clock())
0