Submission #57333067


Source Code Expand

Copy
class BIT
def initialize n
@a = [0]*(n+1) # 1-indexed internally
end
def [] i
i += 1
x = 0
while 0<i
x = @a[i] if x<@a[i]
i &= i-1
end
return x
end
def []= i,x
i += 1
while i<@a.size
@a[i] = x if @a[i]<x
i += i&-i
end
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
class BIT
	def initialize n
		@a = [0]*(n+1) # 1-indexed internally
	end

	def [] i
		i += 1
		x = 0
		while 0<i
			x = @a[i] if x<@a[i]
			i &= i-1
		end
		return x
	end
 
	def []= i,x
		i += 1
		while i<@a.size
			@a[i] = x if @a[i]<x
			i += i&-i
		end
	end
end

(H,W,N),*RC = $<.map{|ln| ln.split.map(&:to_i) }
dm = 0
dm += 1 and RC<<[1,1] if RC.none?([1,1])
dm += 1 and RC<<[H,W] if RC.none?([H,W])
R2C = RC.group_by{|r,|r}.transform_values{|rcs| rcs.map{_2}.sort }
Rs = R2C.keys.sort

X2RC = [[0,0]]
C2X = BIT.new W+2
Rs.each{|r|
	cs = R2C[r]
	cs.each{|c|
		x = C2X[c] = C2X[c]+1
		X2RC<<[] unless X2RC[x]
		X2RC[x]<<[r,c] if ! X2RC[x][-1] || c<X2RC[x][-1][1]
	}
}
X2RC.shift
(X2RC.size-2).downto(0){|i|
	rcs = X2RC[i]
	r1,c1 = X2RC[i+1][-1]
	rcs.pop while (r0,c0 = rcs[-1]) and c1<c0||r1<r0||c0==c1&&r0==r1
}
X2RC.map!(&:last)
X = X2RC.size-dm

puts X,X2RC.each_cons(2).map{|(r0,c0),(r1,c1)|
	?D*(r1-r0)+?R*(c1-c0)
}*''

Submission Info

Submission Time
Task F - Gather Coins
User ds14050
Language Ruby (ruby 3.2.2)
Score 500
Code Size 980 Byte
Status AC
Exec Time 653 ms
Memory 107612 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 44
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 02_random2_05.txt, 02_random2_06.txt, 02_random2_07.txt, 02_random2_08.txt, 02_random2_09.txt, 03_random3_00.txt, 03_random3_01.txt, 03_random3_02.txt, 03_random3_03.txt, 03_random3_04.txt, 03_random3_05.txt, 03_random3_06.txt, 03_random3_07.txt, 03_random3_08.txt, 03_random3_09.txt, 04_full_00.txt, 04_full_01.txt, 04_full_02.txt, 05_handmade_00.txt, 05_handmade_01.txt, 05_handmade_02.txt, 05_handmade_03.txt, 05_handmade_04.txt, 05_handmade_05.txt, 05_handmade_06.txt, 05_handmade_07.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 91 ms 17140 KB
00_sample_01.txt AC 42 ms 17136 KB
00_sample_02.txt AC 41 ms 17184 KB
01_random_00.txt AC 492 ms 55048 KB
01_random_01.txt AC 472 ms 54856 KB
01_random_02.txt AC 426 ms 51688 KB
01_random_03.txt AC 274 ms 39908 KB
01_random_04.txt AC 114 ms 25160 KB
01_random_05.txt AC 526 ms 64768 KB
01_random_06.txt AC 512 ms 65248 KB
01_random_07.txt AC 526 ms 64904 KB
01_random_08.txt AC 528 ms 64868 KB
01_random_09.txt AC 520 ms 65072 KB
02_random2_00.txt AC 603 ms 87824 KB
02_random2_01.txt AC 606 ms 87988 KB
02_random2_02.txt AC 586 ms 81420 KB
02_random2_03.txt AC 579 ms 83176 KB
02_random2_04.txt AC 580 ms 84792 KB
02_random2_05.txt AC 570 ms 82612 KB
02_random2_06.txt AC 588 ms 80656 KB
02_random2_07.txt AC 572 ms 78268 KB
02_random2_08.txt AC 545 ms 66872 KB
02_random2_09.txt AC 552 ms 66288 KB
03_random3_00.txt AC 481 ms 62460 KB
03_random3_01.txt AC 484 ms 62008 KB
03_random3_02.txt AC 480 ms 62220 KB
03_random3_03.txt AC 481 ms 62152 KB
03_random3_04.txt AC 481 ms 62024 KB
03_random3_05.txt AC 477 ms 62052 KB
03_random3_06.txt AC 498 ms 62252 KB
03_random3_07.txt AC 499 ms 62140 KB
03_random3_08.txt AC 483 ms 61876 KB
03_random3_09.txt AC 483 ms 62268 KB
04_full_00.txt AC 99 ms 22120 KB
04_full_01.txt AC 257 ms 34516 KB
04_full_02.txt AC 149 ms 26864 KB
05_handmade_00.txt AC 650 ms 85436 KB
05_handmade_01.txt AC 647 ms 85476 KB
05_handmade_02.txt AC 515 ms 75556 KB
05_handmade_03.txt AC 653 ms 107612 KB
05_handmade_04.txt AC 554 ms 62432 KB
05_handmade_05.txt AC 471 ms 58184 KB
05_handmade_06.txt AC 517 ms 82832 KB
05_handmade_07.txt AC 44 ms 19848 KB


2025-04-18 (Fri)
14:42:19 +00:00