結果

問題 No.1369 交換門松列・竹
ユーザー maimai
提出日時 2020-11-03 16:04:45
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 1,388 bytes
コンパイル時間 69 ms
コンパイル使用メモリ 11,724 KB
実行使用メモリ 27,540 KB
最終ジャッジ日時 2023-09-29 15:09:40
合計ジャッジ時間 22,869 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
15,364 KB
testcase_01 AC 84 ms
15,316 KB
testcase_02 AC 81 ms
15,352 KB
testcase_03 AC 79 ms
15,180 KB
testcase_04 AC 81 ms
15,316 KB
testcase_05 AC 85 ms
15,188 KB
testcase_06 AC 81 ms
15,328 KB
testcase_07 AC 83 ms
15,216 KB
testcase_08 AC 84 ms
15,312 KB
testcase_09 AC 84 ms
15,344 KB
testcase_10 AC 82 ms
15,224 KB
testcase_11 AC 81 ms
15,276 KB
testcase_12 AC 84 ms
15,140 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 257 ms
26,884 KB
testcase_16 AC 674 ms
27,016 KB
testcase_17 AC 1,030 ms
27,036 KB
testcase_18 AC 674 ms
26,936 KB
testcase_19 AC 255 ms
26,944 KB
testcase_20 AC 1,630 ms
27,180 KB
testcase_21 AC 259 ms
26,888 KB
testcase_22 AC 1,608 ms
26,964 KB
testcase_23 AC 689 ms
26,976 KB
testcase_24 TLE -
testcase_25 AC 1,730 ms
16,120 KB
testcase_26 AC 1,521 ms
16,172 KB
testcase_27 AC 1,510 ms
16,076 KB
testcase_28 TLE -
testcase_29 TLE -
testcase_30 AC 132 ms
27,540 KB
testcase_31 AC 129 ms
26,208 KB
testcase_32 AC 158 ms
15,592 KB
testcase_33 AC 978 ms
20,412 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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

# - - - - -

def solve(n, arr)
    
    not_kado_idxs = arr.each_cons(3).each_with_index.map{|a,i| 🎍(*a) ? nil : i}.compact
    
    return false if not_kado_idxs.size > 20
    
    validate_idxs = not_kado_idxs.map{|i| (-1..0).map{|e|i+e}.to_a}.flatten.uniq.select{|i| 0 <= i && i < n-2}
    
    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 ||= validate_idxs.each.all?{|x| 🎍(arr[x], arr[x+1], arr[x+2])} &&
                       (-2..0).map{|e|i+e}.select{|i| 0 <= i && i < n-2}.all?{|x| 🎍(arr[x], arr[x+1], arr[x+2])}
                arr[i], arr[j] = arr[j], arr[i]
            end
        end
    end
    ok
end



line1 = gets.chomp!
abort unless line1 =~ /^\d+$/

t = line1.to_i

t.times do |i|
  linea = gets.chomp!
  lineb = gets.chomp!
  abort "#{i}: n format" unless linea =~ /^\d+$/
  abort "#{i}: A format" unless lineb =~ /^\d+(?: \d+)+$/
  
  n = linea.to_i
  arr = lineb.split.map(&:to_i)
  
  abort "#{i}: n"    unless n == arr.size 
  abort "#{i}: A[i]" unless arr.all?{|a| 1 <= a && a <= n}
  abort "#{i}: 🎍" if arr.each_cons(3).all?{|a| 🎍(*a)}
  puts solve(n, arr) ? 'Yes' : 'No'
end
abort 'break' if gets

0