結果

問題 No.274 The Wall
ユーザー 👑 obakyanobakyan
提出日時 2019-11-10 19:03:45
言語 Lua
(LuaJit 2.1.1696795921)
結果
WA  
実行時間 -
コード長 1,017 bytes
コンパイル時間 138 ms
コンパイル使用メモリ 5,332 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-13 07:50:30
合計ジャッジ時間 2,060 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

local n, m = io.read("*n", "*n")
local t = {}
local norm = {}
local inv = {}
for i = 1, n do
  local l, r = io.read("*n", "*n")
  t[i] = {l + 1, r + 1}
end
table.sort(t, function(x, y)
  if x[2] ~= y[2] then
    return x[1] < y[1]
  else
    return x[2] < y[2]
  end
end)
local used = {}
for i = 1, m do
  used[i] = false
end
while 0 < #t do
  local v = t[#t]
  table.remove(t)
  local vl = v[1]
  table.insert(norm, v)
  for i = #t, 1, -1 do
    if vl <= t[i][2] then
      table.insert(inv, t[i])
      table.remove(t)
    else
      break
    end
  end
end
local isok = true
for i = 1, #norm do
  for j = norm[i][1], norm[i][2] do
    if used[j] then
      isok = false
      break
    else
      used[j] = true
    end
  end
  if not isok then break end
end
for i = 1, #inv do
  local l = m + 1 - inv[i][2]
  local r = m + 1 - inv[i][1]
  for j = l, r do
    if used[j] then
      isok = false
      break
    else
      used[j] = true
    end
  end
  if not isok then break end
end
print(isok and "YES" or "NO")
0