Submission #14164516


Source Code Expand

Copy
(N,K,D),A = 2.times.map{ gets.split.map(&:to_i) }
m = A.map.with_index{|a,i| [a,i,i,i+1,nil,nil] }
m = m.each_slice(2).map{|l,r|
r = l unless r
min = l[0]<r[0]||l[0]==r[0]&&l[1]<r[1] ? l : r
next [min[0],min[1],l[2],r[3],l,r]
} until 1 == m.size
Min = lambda{|b,e|
next nil unless b<e
q,a,i = [m[0]],nil,nil
until q.empty?
a_,i_,b_,e_,l,r = q.shift
if b<=b_ && e_<=e
(a,i = a_,i_) if (! a || a_<a || a_==a && i_<i)
else
q << l if b<l[3]
q << r if r[2]<e
end
end
next a,i
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
(N,K,D),A = 2.times.map{ gets.split.map(&:to_i) }

m = A.map.with_index{|a,i| [a,i,i,i+1,nil,nil] }
m = m.each_slice(2).map{|l,r|
	r = l unless r
	min = l[0]<r[0]||l[0]==r[0]&&l[1]<r[1] ? l : r
	next [min[0],min[1],l[2],r[3],l,r]
} until 1 == m.size
Min = lambda{|b,e|
	next nil unless b<e
	q,a,i = [m[0]],nil,nil
	until q.empty?
		a_,i_,b_,e_,l,r = q.shift
		if b<=b_ && e_<=e
			(a,i = a_,i_) if (! a || a_<a || a_==a && i_<i)
		else
			q << l if b<l[3]
			q << r if r[2]<e
		end
	end
	next a,i
}

b,B = -D,[]
K.downto(1){|k|
	min,i = Min[b+D, N-D*(k-1)]
	break unless min
	B << min
	b = i
}
puts(B.size==K ? B.join(" ") : -1)

Submission Info

Submission Time
Task L - Lexicographically Minimum
User ds14050
Language Ruby (2.7.1)
Score 6
Code Size 660 Byte
Status AC
Exec Time 1293 ms
Memory 93824 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 6 / 6
Status
AC × 4
AC × 41
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt, s4.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, s1.txt, s2.txt, s3.txt, s4.txt
Case Name Status Exec Time Memory
01.txt AC 406 ms 50044 KB
02.txt AC 259 ms 41752 KB
03.txt AC 142 ms 26460 KB
04.txt AC 100 ms 29964 KB
05.txt AC 164 ms 44576 KB
06.txt AC 368 ms 80968 KB
07.txt AC 179 ms 61452 KB
08.txt AC 137 ms 35368 KB
09.txt AC 67 ms 17324 KB
10.txt AC 176 ms 60892 KB
11.txt AC 201 ms 68448 KB
12.txt AC 192 ms 42116 KB
13.txt AC 200 ms 69152 KB
14.txt AC 199 ms 69196 KB
15.txt AC 53 ms 14180 KB
16.txt AC 51 ms 14236 KB
17.txt AC 57 ms 14324 KB
18.txt AC 85 ms 17716 KB
19.txt AC 288 ms 40052 KB
20.txt AC 652 ms 89696 KB
21.txt AC 465 ms 86120 KB
22.txt AC 653 ms 86236 KB
23.txt AC 202 ms 70812 KB
24.txt AC 203 ms 70560 KB
25.txt AC 187 ms 64220 KB
26.txt AC 146 ms 44100 KB
27.txt AC 682 ms 86256 KB
28.txt AC 203 ms 70616 KB
29.txt AC 611 ms 86248 KB
30.txt AC 413 ms 87848 KB
31.txt AC 1132 ms 91264 KB
32.txt AC 1182 ms 92292 KB
33.txt AC 1096 ms 90444 KB
34.txt AC 921 ms 88024 KB
35.txt AC 450 ms 87456 KB
36.txt AC 1293 ms 93824 KB
37.txt AC 377 ms 86372 KB
s1.txt AC 51 ms 14060 KB
s2.txt AC 52 ms 14220 KB
s3.txt AC 51 ms 14148 KB
s4.txt AC 53 ms 14044 KB


2025-04-07 (Mon)
23:50:40 +00:00