Submission #19868017
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 = n - k + 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 if 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 | 766 Byte |
Status | WA |
Exec Time | 226 ms |
Memory | 47132 KB |
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 700 | ||||||
Status |
|
|
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 | 58 ms | 14096 KB |
01-02.txt | AC | 60 ms | 13952 KB |
01-03.txt | AC | 191 ms | 32752 KB |
01-04.txt | WA | 187 ms | 32672 KB |
01-05.txt | WA | 142 ms | 28804 KB |
01-06.txt | AC | 166 ms | 31204 KB |
01-07.txt | AC | 210 ms | 33992 KB |
01-08.txt | WA | 226 ms | 33864 KB |
01-09.txt | WA | 208 ms | 34040 KB |
01-10.txt | WA | 212 ms | 33968 KB |
01-11.txt | WA | 224 ms | 34132 KB |
01-12.txt | WA | 206 ms | 33836 KB |
01-13.txt | WA | 204 ms | 33968 KB |
01-14.txt | AC | 221 ms | 35080 KB |
01-15.txt | WA | 206 ms | 34556 KB |
01-16.txt | WA | 214 ms | 34812 KB |
01-17.txt | AC | 225 ms | 44556 KB |
01-18.txt | WA | 198 ms | 40556 KB |
01-19.txt | WA | 204 ms | 40368 KB |
01-20.txt | AC | 200 ms | 35148 KB |
01-21.txt | AC | 187 ms | 40532 KB |
01-22.txt | AC | 220 ms | 47132 KB |
01-23.txt | WA | 188 ms | 40736 KB |
01-24.txt | WA | 186 ms | 40884 KB |
01-25.txt | AC | 171 ms | 41664 KB |
01-26.txt | AC | 178 ms | 41184 KB |
01-27.txt | AC | 190 ms | 39700 KB |
01-28.txt | AC | 176 ms | 41448 KB |
01-29.txt | AC | 172 ms | 40928 KB |
sample-01.txt | AC | 59 ms | 14032 KB |
sample-02.txt | AC | 62 ms | 13960 KB |
sample-03.txt | AC | 63 ms | 13944 KB |