結果

問題 No.1768 The frog in the well knows the great ocean.
ユーザー tomerun
提出日時 2021-11-26 23:32:09
言語 Crystal
(1.14.0)
結果
WA  
実行時間 -
コード長 480 bytes
コンパイル時間 14,606 ms
コンパイル使用メモリ 294,200 KB
実行使用メモリ 26,352 KB
最終ジャッジ日時 2024-06-29 19:05:38
合計ジャッジ時間 15,629 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 7 WA * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

read_line.to_i.times do
  puts solve() ? "Yes" : "No"
end

def solve
  n = read_line.to_i
  a = read_line.split.map(&.to_i)
  b = read_line.split.map(&.to_i)
  c = Array.new(n, 0)
  st = [0]
  n.times do |i|
    st << a[i] if a[i] > st[-1]
    while st[-1] > b[i]
      st.pop
    end
    c[i] = st[-1]
  end
  st = [0]
  (n - 1).downto(0) do |i|
    st << a[i] if a[i] > st[-1]
    while st[-1] > b[i]
      st.pop
    end
    c[i] = {c[i], st[-1]}.max
  end
  return b == c
end
0