結果

問題 No.629 グラフの中に眠る門松列
ユーザー simansiman
提出日時 2021-10-04 14:50:15
言語 Ruby
(3.2.2)
結果
AC  
実行時間 168 ms / 4,000 ms
コード長 502 bytes
コンパイル時間 222 ms
コンパイル使用メモリ 11,152 KB
実行使用メモリ 15,528 KB
最終ジャッジ日時 2023-09-29 20:03:33
合計ジャッジ時間 6,156 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
15,120 KB
testcase_01 AC 76 ms
15,188 KB
testcase_02 AC 75 ms
15,248 KB
testcase_03 AC 76 ms
15,064 KB
testcase_04 AC 75 ms
15,120 KB
testcase_05 AC 75 ms
15,064 KB
testcase_06 AC 77 ms
15,328 KB
testcase_07 AC 80 ms
15,320 KB
testcase_08 AC 79 ms
15,140 KB
testcase_09 AC 77 ms
15,260 KB
testcase_10 AC 76 ms
15,160 KB
testcase_11 AC 75 ms
15,136 KB
testcase_12 AC 78 ms
15,228 KB
testcase_13 AC 74 ms
15,248 KB
testcase_14 AC 79 ms
15,008 KB
testcase_15 AC 78 ms
15,088 KB
testcase_16 AC 74 ms
15,232 KB
testcase_17 AC 77 ms
15,260 KB
testcase_18 AC 75 ms
15,044 KB
testcase_19 AC 76 ms
15,088 KB
testcase_20 AC 74 ms
15,120 KB
testcase_21 AC 168 ms
15,360 KB
testcase_22 AC 79 ms
15,232 KB
testcase_23 AC 123 ms
15,484 KB
testcase_24 AC 82 ms
15,444 KB
testcase_25 AC 143 ms
15,192 KB
testcase_26 AC 132 ms
15,144 KB
testcase_27 AC 85 ms
15,272 KB
testcase_28 AC 77 ms
15,156 KB
testcase_29 AC 84 ms
15,440 KB
testcase_30 AC 92 ms
15,316 KB
testcase_31 AC 91 ms
15,528 KB
testcase_32 AC 85 ms
15,460 KB
testcase_33 AC 92 ms
15,488 KB
testcase_34 AC 86 ms
15,440 KB
testcase_35 AC 86 ms
15,368 KB
testcase_36 AC 85 ms
15,504 KB
testcase_37 AC 91 ms
15,420 KB
testcase_38 AC 87 ms
15,496 KB
testcase_39 AC 85 ms
15,448 KB
testcase_40 AC 86 ms
15,256 KB
testcase_41 AC 84 ms
15,316 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, M = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)

E = Hash.new { |h, k| h[k] = [] }

M.times do
  u, v = gets.split.map(&:to_i)
  E[u] << v
  E[v] << u
end

1.upto(N) do |v|
  next if E[v].size == 1
  a1 = A[v - 1]

  E[v].combination(2) do |i, j|
    a2 = A[i - 1]
    a3 = A[j - 1]
    next if a1 == a2
    next if a1 == a3
    next if a2 == a3

    if a2 < a1 && a1 > a3
      puts 'YES'
      exit
    end

    if a2 > a1 && a1 < a3
      puts 'YES'
      exit
    end
  end
end

puts 'NO'
0