結果

問題 No.1768 The frog in the well knows the great ocean.
ユーザー tomeruntomerun
提出日時 2021-11-26 23:32:09
言語 Crystal
(1.11.2)
結果
WA  
実行時間 -
コード長 480 bytes
コンパイル時間 20,515 ms
コンパイル使用メモリ 254,260 KB
実行使用メモリ 28,688 KB
最終ジャッジ日時 2023-09-12 06:00:44
合計ジャッジ時間 23,077 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,380 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 51 ms
22,168 KB
testcase_13 WA -
testcase_14 AC 53 ms
20,528 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 60 ms
28,688 KB
testcase_20 AC 60 ms
27,756 KB
testcase_21 AC 2 ms
4,384 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 47 ms
26,872 KB
testcase_27 AC 2 ms
4,384 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|
    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