結果
問題 | No.1768 The frog in the well knows the great ocean. |
ユーザー | tomerun |
提出日時 | 2021-11-26 23:48:22 |
言語 | Crystal (1.11.2) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,915 bytes |
コンパイル時間 | 10,891 ms |
コンパイル使用メモリ | 295,032 KB |
実行使用メモリ | 26,848 KB |
最終ジャッジ日時 | 2024-06-29 19:08:30 |
合計ジャッジ時間 | 14,292 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 7 ms
6,940 KB |
testcase_02 | AC | 7 ms
6,940 KB |
testcase_03 | AC | 7 ms
6,940 KB |
testcase_04 | AC | 7 ms
6,940 KB |
testcase_05 | AC | 7 ms
6,944 KB |
testcase_06 | AC | 105 ms
10,240 KB |
testcase_07 | AC | 108 ms
13,184 KB |
testcase_08 | AC | 106 ms
10,368 KB |
testcase_09 | AC | 105 ms
10,240 KB |
testcase_10 | AC | 107 ms
15,904 KB |
testcase_11 | AC | 111 ms
17,648 KB |
testcase_12 | AC | 110 ms
17,592 KB |
testcase_13 | AC | 111 ms
17,644 KB |
testcase_14 | AC | 112 ms
17,644 KB |
testcase_15 | AC | 114 ms
17,648 KB |
testcase_16 | AC | 121 ms
25,852 KB |
testcase_17 | AC | 121 ms
25,116 KB |
testcase_18 | AC | 122 ms
25,980 KB |
testcase_19 | AC | 124 ms
26,492 KB |
testcase_20 | AC | 121 ms
25,248 KB |
testcase_21 | AC | 1 ms
6,944 KB |
testcase_22 | AC | 2 ms
6,940 KB |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | AC | 84 ms
26,848 KB |
testcase_26 | AC | 82 ms
26,836 KB |
testcase_27 | AC | 2 ms
6,940 KB |
ソースコード
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, false) set = Set(Int32).new q = PriorityQueue(Int32).new(n) n.times do |i| if a[i] > b[i] return false end set << a[i] q.add(a[i]) while q.size > 0 && q.top > b[i] set.delete(q.top) q.pop end c[i] ||= set.includes?(b[i]) end set.clear q.clear (n - 1).downto(0) do |i| set << a[i] q.add(a[i]) while q.size > 0 && q.top > b[i] set.delete(q.top) q.pop end c[i] ||= set.includes?(b[i]) end return c.all? { |v| v } end class PriorityQueue(T) def initialize(capacity : Int32) @elem = Array(T).new(capacity) end def initialize(list : Enumerable(T)) @elem = list.to_a 1.upto(size - 1) { |i| fixup(i) } end def size @elem.size end def add(v) @elem << v fixup(size - 1) end def top @elem[0] end def pop ret = @elem[0] last = @elem.pop if size > 0 @elem[0] = last fixdown(0) end ret end def clear @elem.clear end def decrease_top(new_value : T) @elem[0] = new_value fixdown(0) end def to_s(io : IO) io << @elem end private def fixup(index : Int32) while index > 0 parent = (index - 1) // 2 break if @elem[parent] >= @elem[index] @elem[parent], @elem[index] = @elem[index], @elem[parent] index = parent end end private def fixdown(index : Int32) while true left = index * 2 + 1 break if left >= size right = index * 2 + 2 child = right >= size || @elem[left] > @elem[right] ? left : right if @elem[child] > @elem[index] @elem[child], @elem[index] = @elem[index], @elem[child] index = child else break end end end end