結果

問題 No.1703 Much Matching
ユーザー 👑 obakyanobakyan
提出日時 2022-01-01 21:00:53
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 844 ms / 2,000 ms
コード長 1,237 bytes
コンパイル時間 152 ms
コンパイル使用メモリ 5,248 KB
実行使用メモリ 11,648 KB
最終ジャッジ日時 2024-04-18 20:45:04
合計ジャッジ時間 6,020 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 187 ms
6,400 KB
testcase_07 AC 13 ms
5,376 KB
testcase_08 AC 216 ms
6,016 KB
testcase_09 AC 269 ms
6,400 KB
testcase_10 AC 31 ms
5,376 KB
testcase_11 AC 59 ms
5,376 KB
testcase_12 AC 9 ms
5,376 KB
testcase_13 AC 102 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 51 ms
5,376 KB
testcase_16 AC 122 ms
5,504 KB
testcase_17 AC 158 ms
5,376 KB
testcase_18 AC 4 ms
5,376 KB
testcase_19 AC 326 ms
9,088 KB
testcase_20 AC 34 ms
5,376 KB
testcase_21 AC 439 ms
11,008 KB
testcase_22 AC 158 ms
5,888 KB
testcase_23 AC 137 ms
5,376 KB
testcase_24 AC 4 ms
5,376 KB
testcase_25 AC 15 ms
5,376 KB
testcase_26 AC 81 ms
5,376 KB
testcase_27 AC 177 ms
5,376 KB
testcase_28 AC 369 ms
7,040 KB
testcase_29 AC 69 ms
5,376 KB
testcase_30 AC 97 ms
5,376 KB
testcase_31 AC 12 ms
5,376 KB
testcase_32 AC 169 ms
5,376 KB
testcase_33 AC 131 ms
5,376 KB
testcase_34 AC 11 ms
5,376 KB
testcase_35 AC 37 ms
5,376 KB
testcase_36 AC 844 ms
11,648 KB
testcase_37 AC 7 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mmi, mma = math.min, math.max
local mfl = math.floor

local function comp(a, b)
  return a < b
end

local function lower_bound(ary, x)
  local num = #ary
  if num == 0 then return 1 end
  if not comp(ary[1], x) then return 1 end
  if comp(ary[num], x) then return num + 1 end
  local min, max = 1, num
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if comp(ary[mid], x) then
      min = mid
    else
      max = mid
    end
  end
  return max
end

local n, m, q = io.read("*n", "*n", "*n")
local dp1, dp2 = {}, {}
local t = {}
for i = 1, n do
  t[i] = {}
end
for i = 1, q do
  local a, b = io.read("*n", "*n")
  table.insert(t[a], b)
end
for i = 1, n do
  table.sort(t[i])
end
for i = 1, n do
  local src = i % 2 == 1 and dp1 or dp2
  local dst = i % 2 == 1 and dp2 or dp1
  for j = 1, i - 1 do
    dst[j] = src[j]
  end
  dst[i] = m + 1
  for j = i - 1, 1, -1 do
    if src[j] <= m then
      local lb = lower_bound(t[i], src[j] + 1)
      if lb <= #t[i] then
        dst[j + 1] = mmi(dst[j + 1], t[i][lb])
      end
    end
  end
  if 0 < #t[i] then
    dst[1] = mmi(dst[1], t[i][1])
  end
end
local tbl = n % 2 == 1 and dp2 or dp1
for i = n, 1, -1 do
  if tbl[i] <= m then print(i) os.exit() end
end
print(0)
0