結果

問題 No.629 グラフの中に眠る門松列
ユーザー maimai
提出日時 2018-01-06 09:30:46
言語 Ruby
(3.3.0)
結果
AC  
実行時間 2,226 ms / 4,000 ms
コード長 1,579 bytes
コンパイル時間 164 ms
コンパイル使用メモリ 11,308 KB
実行使用メモリ 15,700 KB
最終ジャッジ日時 2023-08-24 22:13:37
合計ジャッジ時間 17,936 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
15,284 KB
testcase_01 AC 78 ms
15,156 KB
testcase_02 AC 80 ms
15,236 KB
testcase_03 AC 79 ms
15,044 KB
testcase_04 AC 77 ms
15,268 KB
testcase_05 AC 78 ms
15,168 KB
testcase_06 AC 79 ms
15,164 KB
testcase_07 AC 80 ms
15,164 KB
testcase_08 AC 78 ms
15,188 KB
testcase_09 AC 79 ms
15,192 KB
testcase_10 AC 78 ms
15,312 KB
testcase_11 AC 79 ms
15,152 KB
testcase_12 AC 78 ms
15,228 KB
testcase_13 AC 78 ms
15,076 KB
testcase_14 AC 79 ms
15,160 KB
testcase_15 AC 79 ms
15,080 KB
testcase_16 AC 78 ms
15,156 KB
testcase_17 AC 78 ms
15,284 KB
testcase_18 AC 78 ms
15,168 KB
testcase_19 AC 78 ms
15,224 KB
testcase_20 AC 77 ms
15,304 KB
testcase_21 AC 226 ms
15,544 KB
testcase_22 AC 80 ms
15,096 KB
testcase_23 AC 151 ms
15,364 KB
testcase_24 AC 99 ms
15,408 KB
testcase_25 AC 2,152 ms
15,512 KB
testcase_26 AC 2,226 ms
15,488 KB
testcase_27 AC 1,250 ms
15,604 KB
testcase_28 AC 100 ms
15,332 KB
testcase_29 AC 135 ms
15,504 KB
testcase_30 AC 410 ms
15,628 KB
testcase_31 AC 200 ms
15,700 KB
testcase_32 AC 159 ms
15,640 KB
testcase_33 AC 2,183 ms
15,660 KB
testcase_34 AC 223 ms
15,496 KB
testcase_35 AC 107 ms
15,340 KB
testcase_36 AC 1,060 ms
15,568 KB
testcase_37 AC 1,092 ms
15,488 KB
testcase_38 AC 1,388 ms
15,532 KB
testcase_39 AC 280 ms
15,556 KB
testcase_40 AC 403 ms
15,344 KB
testcase_41 AC 94 ms
15,432 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

# https://yukicoder.me/submissions/169872

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