結果

問題 No.1707 Simple Range Reverse Problem
ユーザー 👑 obakyanobakyan
提出日時 2022-01-02 23:49:25
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 732 bytes
コンパイル時間 347 ms
コンパイル使用メモリ 6,812 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-20 09:10:09
合計ジャッジ時間 923 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local q = io.read("*n")
local a = {}
local c = {}
local function solve()
  local n = io.read("*n")
  for i = 1, 2 * n do
    a[i] = io.read("*n")
  end
  if a[1] ~= 1 then return false end
  local spos = 0
  for i = 2, n + 1 do
    if i <= n and a[i] ~= i then
      spos = i - 1 break
    elseif i == n + 1 and a[i] ~= 1 then
      spos = i - 1 break
    end
  end
  if 0 < spos then
    local tpos = spos + n
    for i = spos + 1, tpos - 1 do
      local j = spos + tpos - i
      if j <= i then break end
      a[i], a[j] = a[j], a[i]
    end
  end
  for i = 1, n do
    if a[i] ~= i then return false end
    if a[n + i] ~= i then return false end
  end
  return true
end
for iq = 1, q do
  print(solve() and "Yes" or "No")
end
0