結果

問題 No.1369 交換門松列・竹
ユーザー simansiman
提出日時 2022-11-16 06:35:07
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 805 bytes
コンパイル時間 67 ms
コンパイル使用メモリ 11,856 KB
実行使用メモリ 18,984 KB
最終ジャッジ日時 2023-10-17 06:10:03
合計ジャッジ時間 6,648 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
16,032 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 85 ms
16,032 KB
testcase_04 AC 87 ms
16,032 KB
testcase_05 AC 85 ms
16,032 KB
testcase_06 WA -
testcase_07 AC 86 ms
16,032 KB
testcase_08 WA -
testcase_09 AC 85 ms
16,032 KB
testcase_10 AC 85 ms
16,032 KB
testcase_11 WA -
testcase_12 AC 85 ms
16,032 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 126 ms
18,972 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 123 ms
18,972 KB
testcase_20 AC 133 ms
18,972 KB
testcase_21 AC 139 ms
18,972 KB
testcase_22 AC 114 ms
18,972 KB
testcase_23 WA -
testcase_24 AC 128 ms
18,972 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 109 ms
18,788 KB
testcase_29 AC 110 ms
18,788 KB
testcase_30 AC 105 ms
18,984 KB
testcase_31 AC 105 ms
18,960 KB
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

T = gets.to_i

def is_kadomatsu(arr)
  arr.each_cons(3).each do |a, b, c|
    return false if a == b
    return false if a == c
    return false if b == c

    return false if a < b && b < c
    return false if a > b && b > c
  end

  true
end

T.times do
  n = gets.to_i
  arr = gets.split.map(&:to_i)

  idx = -1

  1.upto(n - 2) do |i|
    a = arr[i - 1]
    b = arr[i]
    c = arr[i + 1]

    if a == b || a == c || b == c
      idx = i
      break
    end

    next if a < b && b > c
    next if a > b && b < c

    idx = i
    break
  end

  ok = false
  (idx - 1..[idx + 2, n - 2].min).each do |i|
    arr[i], arr[i + 1] = arr[i + 1], arr[i]

    if is_kadomatsu(arr)
      ok = true
    end

    arr[i], arr[i + 1] = arr[i + 1], arr[i]
  end

  if ok
    puts 'Yes'
  else
    puts 'No'
  end
end
0