Submission #68969535


Source Code Expand

Q = gets.to_i
C = Array.new(Q+1){[]}
Qry = (1..Q).map{|q|
	_,x,y = gets.split.map(&:to_i)
	C[x]<<q unless y
	next q,x,y
}
I = [nil]*(Q+1) # x,y の順序
F = lambda{|i,x;c|
	I[x] = i += 1
	cs = C[x]
	i = F[i,c] while c = cs.pop
	i
}
F[0,0]

A = []
Nx = [nil]*(Q+1)
while (q,x,y = Qry.shift)
	if y
		x,y = y,x if I[y]<I[x]
		s = 0
		nx = Nx[x]
		Nx[x] = y
		until nx==y
			s += nx
			nx = Nx[nx]
		end
		A<<s
	else
		# x -> q -> Nx[x]
		Nx[q] = Nx[x]
		Nx[x] = q
	end
end
puts A

Submission Info

Submission Time
Task F - Erase between X and Y
User ds14050
Language Ruby (ruby 3.2.2)
Score 525
Code Size 514 Byte
Status AC
Exec Time 924 ms
Memory 352228 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 525 / 525
Status
AC × 3
AC × 36
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, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 03_handmade_00.txt, 03_handmade_01.txt, 03_handmade_02.txt, 03_handmade_03.txt, 03_handmade_04.txt, 03_handmade_05.txt, 03_handmade_06.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 122 ms 17060 KiB
00_sample_01.txt AC 43 ms 16788 KiB
00_sample_02.txt AC 44 ms 17140 KiB
01_random_00.txt AC 884 ms 89816 KiB
01_random_01.txt AC 915 ms 97032 KiB
01_random_02.txt AC 883 ms 102844 KiB
01_random_03.txt AC 895 ms 107740 KiB
01_random_04.txt AC 917 ms 129068 KiB
01_random_05.txt AC 865 ms 114420 KiB
01_random_06.txt AC 882 ms 117352 KiB
01_random_07.txt AC 869 ms 119340 KiB
01_random_08.txt AC 869 ms 121112 KiB
01_random_09.txt AC 865 ms 122424 KiB
01_random_10.txt AC 857 ms 122396 KiB
01_random_11.txt AC 849 ms 122232 KiB
01_random_12.txt AC 825 ms 121708 KiB
01_random_13.txt AC 854 ms 120068 KiB
01_random_14.txt AC 824 ms 116840 KiB
01_random_15.txt AC 781 ms 115448 KiB
01_random_16.txt AC 808 ms 111988 KiB
01_random_17.txt AC 736 ms 108044 KiB
01_random_18.txt AC 744 ms 103344 KiB
01_random_19.txt AC 722 ms 97556 KiB
01_random_20.txt AC 921 ms 91836 KiB
02_random2_00.txt AC 817 ms 188064 KiB
02_random2_01.txt AC 765 ms 201120 KiB
02_random2_02.txt AC 768 ms 207460 KiB
02_random2_03.txt AC 754 ms 211808 KiB
02_random2_04.txt AC 701 ms 216388 KiB
03_handmade_00.txt AC 44 ms 17076 KiB
03_handmade_01.txt AC 802 ms 350812 KiB
03_handmade_02.txt AC 669 ms 86764 KiB
03_handmade_03.txt AC 775 ms 352228 KiB
03_handmade_04.txt AC 924 ms 224376 KiB
03_handmade_05.txt AC 874 ms 91472 KiB
03_handmade_06.txt AC 837 ms 159664 KiB