結果

問題 No.1369 交換門松列・竹
ユーザー maimai
提出日時 2019-09-28 12:01:12
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 573 bytes
コンパイル時間 272 ms
コンパイル使用メモリ 11,448 KB
実行使用メモリ 15,480 KB
最終ジャッジ日時 2023-09-29 15:04:27
合計ジャッジ時間 5,397 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 80 ms
15,320 KB
testcase_08 WA -
testcase_09 AC 77 ms
15,172 KB
testcase_10 AC 79 ms
15,144 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 78 ms
15,220 KB
testcase_21 WA -
testcase_22 AC 78 ms
15,272 KB
testcase_23 WA -
testcase_24 AC 78 ms
15,340 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 77 ms
15,320 KB
testcase_29 AC 78 ms
15,176 KB
testcase_30 AC 78 ms
15,220 KB
testcase_31 AC 78 ms
15,336 KB
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def 🎍(a,b,c)
    a != c && ((a < b && b > c) || (a > b && b < c))
end

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

not_kado_idxs = arr.each_cons(3).each_with_index.map{|a,i| 🎍(*a) ? nil : i}.compact

if not_kado_idxs.size > 20
    puts 'No'
end

ok = false
n.times do |i|
    not_kado_idxs.each do |ji|
        3.times do |jj|
            j = ji+jj
            next if i == j
            arr[i], arr[j] = arr[j], arr[i]
            ok ||= arr.each_cons(3).all?{|a| 🎍(*a)}
            arr[i], arr[j] = arr[j], arr[i]
        end
    end
end

puts ok ? 'Yes' : 'No'
0