結果

問題 No.1707 Simple Range Reverse Problem
コンテスト
ユーザー kou_kkk
提出日時 2026-11-04 08:19:18
言語 Nim
(2.2.12 + ACL)
コンパイル:
nim --nimcache=~ --hints:off -o:a.out -d:release cpp _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
+ 414µs
コード長 631 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,606 ms
コンパイル使用メモリ 68,936 KB
実行使用メモリ 9,904 KB
最終ジャッジ日時 2026-11-04 08:19:25
合計ジャッジ時間 6,195 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge7_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sequtils, strutils

proc solve(): bool =
  let
    n = parseInt readLine stdin
    a = stdin.readLine.split.map parseInt
  var
    l = 0
    r = a.high
    x1 = 1
    x2 = n

  if a[0] != 1: return false
  if a[^1] != n: return false
  for i in 1..a.high:
    let d = (a[i] - a[i.pred]).abs
    if d != 1 and d != n.pred: return false

  while a[l] == x1:
    inc l
    inc x1
  while r >= 0 and a[r] == x2:
    dec r
    dec x2
  while a[l] == x2:
    inc l
    dec x2
  while r >= 0 and a[r] == x1:
    dec r
    inc x1
  return l > r

let t = parseInt readLine stdin

for _ in 0 ..< t:
  echo if solve(): "Yes" else: "No"
0