結果

問題 No.1369 交換門松列・竹
ユーザー maimai
提出日時 2020-11-03 17:00:44
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 1,496 bytes
コンパイル時間 52 ms
コンパイル使用メモリ 11,592 KB
実行使用メモリ 27,508 KB
最終ジャッジ日時 2023-09-29 15:10:37
合計ジャッジ時間 21,066 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,212 KB
testcase_08 WA -
testcase_09 AC 80 ms
15,236 KB
testcase_10 AC 80 ms
15,444 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 TLE -
testcase_21 WA -
testcase_22 TLE -
testcase_23 WA -
testcase_24 TLE -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 TLE -
testcase_29 TLE -
testcase_30 AC 129 ms
27,508 KB
testcase_31 AC 130 ms
26,268 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

# - - - - -

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| (-3..2).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])} &&
                       (-3..2).map{|e|i+e}.select{|i| 0 <= i && i < n-2}.all?{|x| 🎍(arr[x], arr[x+1], arr[x+2])}
                if ok; p arr; exit; end
                arr[i], arr[j] = arr[j], arr[i]
            end
        end
    end
    ok
end



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

t = line1.to_i

n_total = 0

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)
  n_total += n
  
  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

abort 'n_total' unless n_total <= 50000
0