結果

問題 No.629 グラフの中に眠る門松列
ユーザー maimai
提出日時 2017-04-30 01:35:29
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 1,116 bytes
コンパイル時間 240 ms
コンパイル使用メモリ 11,124 KB
実行使用メモリ 15,632 KB
最終ジャッジ日時 2023-10-12 19:13:02
合計ジャッジ時間 19,234 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
15,076 KB
testcase_01 AC 84 ms
15,216 KB
testcase_02 AC 83 ms
15,080 KB
testcase_03 WA -
testcase_04 AC 84 ms
15,252 KB
testcase_05 WA -
testcase_06 AC 84 ms
15,072 KB
testcase_07 AC 83 ms
15,152 KB
testcase_08 AC 82 ms
15,024 KB
testcase_09 WA -
testcase_10 AC 83 ms
15,256 KB
testcase_11 AC 82 ms
15,124 KB
testcase_12 WA -
testcase_13 AC 83 ms
15,160 KB
testcase_14 AC 83 ms
15,160 KB
testcase_15 AC 82 ms
14,996 KB
testcase_16 AC 82 ms
15,100 KB
testcase_17 AC 83 ms
15,212 KB
testcase_18 AC 83 ms
15,088 KB
testcase_19 AC 82 ms
15,168 KB
testcase_20 AC 82 ms
15,084 KB
testcase_21 AC 229 ms
15,200 KB
testcase_22 AC 86 ms
15,164 KB
testcase_23 AC 159 ms
15,232 KB
testcase_24 AC 101 ms
15,324 KB
testcase_25 AC 1,607 ms
15,388 KB
testcase_26 AC 1,692 ms
15,384 KB
testcase_27 WA -
testcase_28 AC 101 ms
15,220 KB
testcase_29 AC 612 ms
15,412 KB
testcase_30 AC 331 ms
15,500 KB
testcase_31 WA -
testcase_32 AC 1,360 ms
15,632 KB
testcase_33 AC 1,645 ms
15,484 KB
testcase_34 AC 651 ms
15,328 KB
testcase_35 AC 107 ms
15,184 KB
testcase_36 AC 1,080 ms
15,416 KB
testcase_37 AC 825 ms
15,480 KB
testcase_38 AC 1,057 ms
15,408 KB
testcase_39 AC 341 ms
15,520 KB
testcase_40 AC 321 ms
15,420 KB
testcase_41 AC 97 ms
15,240 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

line = gets.chomp!
abort "line 1 format error" unless line=~/^\d+ \d+$/
n,m = line.split.map &:to_i

line = gets.chomp!
abort "line 2 format error" unless line=~/^\d+(?: \d+)*$/
aa = line.split.map &:to_i
abort "line 2 vector_size error" unless aa.size == n
aa.unshift(nil)

edges = []
m.times{|i|
    line = gets.chomp!
    abort "line #{i+3} format error" unless line=~/^\d+ \d+$/
    edges << line.split.map(&:to_i)
}
abort "too many lines" unless !gets


def yes;puts "YES";exit(0);end
def no ;puts "NO"; exit(0);end

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


# 辺集合から2つ選ぶ組み合わせを全列挙
edges.combination(2){|pair|
    
    if pair[0][0] == pair[1][0]
        # pair[0][1] -> (pair[0][0] == pair[1][0]) -> pair[1][1] となっているケース
        yes if kadomatu?(aa[pair[0][1]], aa[pair[0][0]], aa[pair[1][1]])
        
    elsif pair[0][0] == pair[1][1]
        # pair[0][1] -> (pair[0][0] == pair[1][1]) -> pair[1][0] となっているケース
        yes if kadomatu?(aa[pair[0][1]], aa[pair[1][1]], aa[pair[1][0]])
        
    end
}

no

0