結果

問題 No.1768 The frog in the well knows the great ocean.
ユーザー tomeruntomerun
提出日時 2021-11-26 23:36:48
言語 Crystal
(1.11.2)
結果
WA  
実行時間 -
コード長 526 bytes
コンパイル時間 19,671 ms
コンパイル使用メモリ 253,436 KB
実行使用メモリ 29,540 KB
最終ジャッジ日時 2023-09-12 06:02:16
合計ジャッジ時間 22,485 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,456 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 54 ms
20,796 KB
testcase_13 WA -
testcase_14 AC 54 ms
20,776 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 61 ms
27,384 KB
testcase_20 AC 61 ms
28,796 KB
testcase_21 AC 3 ms
4,484 KB
testcase_22 AC 3 ms
4,436 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 49 ms
26,116 KB
testcase_27 AC 2 ms
4,496 KB
権限があれば一括ダウンロードができます

ソースコード

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