結果

問題 No.905 Sorted?
ユーザー Takuya NoguchiTakuya Noguchi
提出日時 2019-10-25 01:36:13
言語 Ruby
(3.3.0)
結果
AC  
実行時間 353 ms / 2,000 ms
コード長 544 bytes
コンパイル時間 65 ms
コンパイル使用メモリ 11,296 KB
実行使用メモリ 30,368 KB
最終ジャッジ日時 2023-09-25 12:49:34
合計ジャッジ時間 6,512 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
15,140 KB
testcase_01 AC 83 ms
15,152 KB
testcase_02 AC 85 ms
15,020 KB
testcase_03 AC 85 ms
15,256 KB
testcase_04 AC 83 ms
15,124 KB
testcase_05 AC 88 ms
15,544 KB
testcase_06 AC 87 ms
15,144 KB
testcase_07 AC 90 ms
15,676 KB
testcase_08 AC 302 ms
22,628 KB
testcase_09 AC 226 ms
20,368 KB
testcase_10 AC 313 ms
25,388 KB
testcase_11 AC 315 ms
23,096 KB
testcase_12 AC 341 ms
22,532 KB
testcase_13 AC 352 ms
30,368 KB
testcase_14 AC 351 ms
30,160 KB
testcase_15 AC 348 ms
27,148 KB
testcase_16 AC 353 ms
27,348 KB
testcase_17 AC 350 ms
27,448 KB
testcase_18 AC 299 ms
27,400 KB
testcase_19 AC 82 ms
15,168 KB
testcase_20 AC 81 ms
15,152 KB
testcase_21 AC 84 ms
15,288 KB
testcase_22 AC 84 ms
15,096 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
A = gets.split.map(&:to_i)
s_i = Array.new(N, 0)
s_d = Array.new(N, 0)
1.upto(A.size - 1).each do |i|
  diff = A[i] - A[i - 1]

  s_i[i] = 1 if diff >= 0
  s_d[i] = 1 if diff <= 0
end

s_i = s_i.inject([]) { |array, n| array << (array.last || 0) + n && array }
s_d = s_d.inject([]) { |array, n| array << (array.last || 0) + n && array }

gets.to_i.times do
  l, r = gets.split.map(&:to_i)
  is_increase = s_i[r] - s_i[l] == r - l
  is_decrease = s_d[r] - s_d[l] == r - l

  puts "#{is_increase ? 1 : 0} #{is_decrease ? 1 : 0}"
end
0