Submission #14275560


Source Code Expand

Copy
(N,K,D),A = 2.times.map{ gets.split.map(&:to_i) }
Less = lambda{|a,b|
next a[0]<b[0] || a[0]==b[0] && a[1]<b[1] ? a : b
}
L = 1<<(A.size-1).bit_length
H = [nil]*(2*L-1)
H.fill([A[-1],A.size-1],A.size-L)
A.each_with_index{|a,i|
H[i-L] = [a,i]
}
(L-2).downto(0){|i|
j = 2*i+1
H[i] = Less[H[j],H[j+1]]
}
Min = lambda{|s,e|
s = 0 if s<0
e = N-1 if N<=e
next nil if e<s
s,e = s+L-1,e+L-1
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
(N,K,D),A = 2.times.map{ gets.split.map(&:to_i) }

Less = lambda{|a,b|
	next a[0]<b[0] || a[0]==b[0] && a[1]<b[1] ? a : b
}
L = 1<<(A.size-1).bit_length
H = [nil]*(2*L-1)
H.fill([A[-1],A.size-1],A.size-L)
A.each_with_index{|a,i|
	H[i-L] = [a,i]
}
(L-2).downto(0){|i|
	j = 2*i+1
	H[i] = Less[H[j],H[j+1]]
}
Min = lambda{|s,e|
	s = 0 if s<0
	e = N-1 if N<=e
	next nil if e<s

	s,e = s+L-1,e+L-1
	m1,m2 = H[s],H[e]
	while 0
		sp,ep = s/2,e/2-1
		break if ep<sp
		m1 = Less[m1,H[sp]]
		m2 = Less[m2,H[ep]]
		s,e = sp,ep
	end
	next Less[m1,m2]
}

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

Submission Info

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

Compile Error

./Main.rb:29: warning: literal in condition

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 180 ms 26764 KB
02.txt AC 134 ms 24380 KB
03.txt AC 92 ms 19044 KB
04.txt AC 87 ms 20428 KB
05.txt AC 120 ms 24156 KB
06.txt AC 206 ms 39780 KB
07.txt AC 156 ms 33456 KB
08.txt AC 112 ms 23460 KB
09.txt AC 61 ms 15140 KB
10.txt AC 159 ms 33236 KB
11.txt AC 178 ms 39152 KB
12.txt AC 125 ms 23740 KB
13.txt AC 179 ms 38572 KB
14.txt AC 175 ms 38500 KB
15.txt AC 56 ms 14156 KB
16.txt AC 56 ms 14136 KB
17.txt AC 59 ms 14272 KB
18.txt AC 70 ms 15396 KB
19.txt AC 135 ms 24340 KB
20.txt AC 426 ms 43648 KB
21.txt AC 220 ms 43896 KB
22.txt AC 259 ms 47764 KB
23.txt AC 181 ms 40344 KB
24.txt AC 180 ms 40232 KB
25.txt AC 166 ms 37148 KB
26.txt AC 124 ms 24544 KB
27.txt AC 262 ms 48008 KB
28.txt AC 181 ms 40144 KB
29.txt AC 246 ms 46108 KB
30.txt AC 205 ms 40668 KB
31.txt AC 626 ms 48308 KB
32.txt AC 649 ms 48860 KB
33.txt AC 608 ms 47908 KB
34.txt AC 504 ms 46116 KB
35.txt AC 223 ms 40976 KB
36.txt AC 700 ms 51032 KB
37.txt AC 189 ms 40328 KB
s1.txt AC 56 ms 14176 KB
s2.txt AC 52 ms 14228 KB
s3.txt AC 53 ms 14300 KB
s4.txt AC 58 ms 13992 KB


2025-04-08 (Tue)
04:14:27 +00:00