結果

問題 No.1707 Simple Range Reverse Problem
ユーザー 👑 obakyan
提出日時 2022-01-02 23:49:25
言語 Lua
(LuaJit 2.1.1734355927)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 732 bytes
コンパイル時間 110 ms
コンパイル使用メモリ 6,692 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-12 04:34:19
合計ジャッジ時間 952 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

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