結果

問題 No.629 グラフの中に眠る門松列
ユーザー maimai
提出日時 2017-04-30 01:41:01
言語 Ruby
(3.3.0)
結果
AC  
実行時間 2,250 ms / 4,000 ms
コード長 1,536 bytes
コンパイル時間 237 ms
コンパイル使用メモリ 11,096 KB
実行使用メモリ 15,608 KB
最終ジャッジ日時 2023-10-12 19:13:54
合計ジャッジ時間 17,846 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
15,252 KB
testcase_01 AC 83 ms
15,092 KB
testcase_02 AC 84 ms
15,144 KB
testcase_03 AC 83 ms
15,264 KB
testcase_04 AC 86 ms
15,148 KB
testcase_05 AC 84 ms
15,232 KB
testcase_06 AC 85 ms
15,032 KB
testcase_07 AC 84 ms
15,028 KB
testcase_08 AC 83 ms
15,000 KB
testcase_09 AC 83 ms
15,060 KB
testcase_10 AC 83 ms
15,248 KB
testcase_11 AC 84 ms
14,996 KB
testcase_12 AC 84 ms
15,216 KB
testcase_13 AC 83 ms
15,076 KB
testcase_14 AC 83 ms
15,148 KB
testcase_15 AC 84 ms
15,216 KB
testcase_16 AC 84 ms
15,220 KB
testcase_17 AC 83 ms
15,024 KB
testcase_18 AC 84 ms
15,196 KB
testcase_19 AC 84 ms
15,176 KB
testcase_20 AC 83 ms
15,108 KB
testcase_21 AC 234 ms
15,296 KB
testcase_22 AC 87 ms
15,248 KB
testcase_23 AC 157 ms
15,304 KB
testcase_24 AC 105 ms
15,536 KB
testcase_25 AC 2,168 ms
15,372 KB
testcase_26 AC 2,250 ms
15,452 KB
testcase_27 AC 1,261 ms
15,492 KB
testcase_28 AC 106 ms
15,420 KB
testcase_29 AC 144 ms
15,456 KB
testcase_30 AC 419 ms
15,400 KB
testcase_31 AC 205 ms
15,372 KB
testcase_32 AC 168 ms
15,608 KB
testcase_33 AC 2,215 ms
15,560 KB
testcase_34 AC 228 ms
15,376 KB
testcase_35 AC 114 ms
15,192 KB
testcase_36 AC 1,086 ms
15,376 KB
testcase_37 AC 1,097 ms
15,260 KB
testcase_38 AC 1,413 ms
15,500 KB
testcase_39 AC 285 ms
15,484 KB
testcase_40 AC 407 ms
15,416 KB
testcase_41 AC 101 ms
15,424 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]])
        
    elsif pair[0][1] == pair[1][0]
        # pair[0][0] -> (pair[0][1] == pair[1][0]) -> pair[1][1] となっているケース
        yes if kadomatu?(aa[pair[0][0]], aa[pair[0][1]], aa[pair[1][1]])
        
    elsif pair[0][1] == pair[1][1]
        # pair[0][0] -> (pair[0][1] == pair[1][1]) -> pair[1][0] となっているケース
        yes if kadomatu?(aa[pair[0][0]], aa[pair[0][1]], aa[pair[1][0]])
        
    end
}

no

0