Submission #19868031


Source Code Expand

Copy
n, k = gets.chomp.split(' ').map(&:to_i)
p    = gets.chomp.split(' ').map(&:to_i)

max = []
min = []
k.times do |i|
  until max.empty?
    break if max.first[0] > p[i]

    max.shift
  end
  until min.empty?
    break if min.first[0] < p[i]

    min.shift
  end
  max << [p[i], i]
  min << [p[i], i]
end

ans = 1
k.upto(n - 1) do |i|
  mi = [10 ** 18, 10 ** 18]
  max.shift if !max.empty? && i - max.first[1] >= k
  mi = min.shift if !min.empty? && i - min.first[1] >= k
  until max.empty?
    break if max.first[0] > p[i]

    max.shift
  end
  until min.empty?
    break if min.first[0] < p[i]

    min.shift
  end
  max << [p[i], i]
  min << [p[i], i]
  ans += 1 unless mi[1] == i - k && max.first[1] == i
end

puts ans

Submission Info

Submission Time
Task B - Sorting a Segment
User coco18000
Language Ruby (2.7.1)
Score 0
Code Size 762 Byte
Status WA
Exec Time 224 ms
Memory 47428 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 700
Status
AC × 3
AC × 18
WA × 14
Set Name Test Cases
Sample sample-01.txt, sample-02.txt, sample-03.txt
All 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, sample-01.txt, sample-02.txt, sample-03.txt
Case Name Status Exec Time Memory
01-01.txt AC 59 ms 14068 KB
01-02.txt AC 59 ms 14272 KB
01-03.txt AC 187 ms 32888 KB
01-04.txt WA 178 ms 33060 KB
01-05.txt WA 137 ms 29012 KB
01-06.txt AC 164 ms 31268 KB
01-07.txt AC 200 ms 34152 KB
01-08.txt WA 224 ms 34200 KB
01-09.txt WA 203 ms 34260 KB
01-10.txt WA 208 ms 34180 KB
01-11.txt WA 217 ms 34164 KB
01-12.txt WA 202 ms 34368 KB
01-13.txt WA 206 ms 34232 KB
01-14.txt AC 215 ms 34732 KB
01-15.txt WA 199 ms 34772 KB
01-16.txt WA 214 ms 34860 KB
01-17.txt AC 214 ms 44816 KB
01-18.txt WA 189 ms 40688 KB
01-19.txt WA 199 ms 40656 KB
01-20.txt AC 198 ms 35416 KB
01-21.txt AC 191 ms 40604 KB
01-22.txt AC 197 ms 47428 KB
01-23.txt WA 182 ms 40960 KB
01-24.txt WA 187 ms 41312 KB
01-25.txt AC 165 ms 41912 KB
01-26.txt AC 180 ms 41452 KB
01-27.txt AC 190 ms 39604 KB
01-28.txt AC 166 ms 41224 KB
01-29.txt AC 161 ms 41416 KB
sample-01.txt AC 56 ms 14224 KB
sample-02.txt AC 60 ms 14224 KB
sample-03.txt AC 58 ms 14200 KB