結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 WA -
testcase_07 AC 14 ms
5,376 KB
testcase_08 WA -
testcase_09 AC 259 ms
6,272 KB
testcase_10 WA -
testcase_11 AC 59 ms
5,376 KB
testcase_12 WA -
testcase_13 AC 101 ms
5,376 KB
testcase_14 WA -
testcase_15 AC 53 ms
5,376 KB
testcase_16 WA -
testcase_17 AC 160 ms
5,376 KB
testcase_18 WA -
testcase_19 AC 322 ms
9,088 KB
testcase_20 WA -
testcase_21 AC 403 ms
11,136 KB
testcase_22 WA -
testcase_23 AC 133 ms
5,376 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 173 ms
5,376 KB
testcase_28 AC 335 ms
7,040 KB
testcase_29 AC 64 ms
5,376 KB
testcase_30 WA -
testcase_31 AC 13 ms
5,376 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 34 ms
5,376 KB
testcase_36 AC 776 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] = n + 1
  for j = i - 1, 1, -1 do
    if src[j] <= n 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] <= n then print(i) os.exit() end
end
print(0)
0