結果

問題 No.1768 The frog in the well knows the great ocean.
ユーザー tomerun
提出日時 2021-11-26 23:36:48
言語 Crystal
(1.14.0)
結果
WA  
実行時間 -
コード長 526 bytes
コンパイル時間 10,946 ms
コンパイル使用メモリ 295,764 KB
実行使用メモリ 26,872 KB
最終ジャッジ日時 2024-06-29 19:07:00
合計ジャッジ時間 13,213 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 8 WA * 19
権限があれば一括ダウンロードができます

ソースコード

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|
    if a[i] > b[i]
      return false
    end
    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