Submission #56570732


Source Code Expand

(N,D),*P = $<.map{|ln| ln.split.map(&:to_i) }
X,Y = P.transpose.map(&:sort)
SX,SY = [X,Y].map{|xs|
	x0 = [-xs[0],0].max
	xs.map!{|x| x+x0 }
	next xs.inject([0]){|sx,x| sx<<sx[-1]+x }
}
GX,GY = [SX,SY].map{|sx| (sx[-1]+N-1)/N }
IX,IY = [[X,GX],[Y,GY]].map{|xs,g|
	xs.bsearch_index{|x| g<=x }||xs.size-1
}
CY = lambda{|d|
	r = (Y[IY]..10**9).bsearch{|y|
		i = Y.bsearch_index{ y<=_1 }||N
		# 左に i 個 / 右に N-i 個
		ls = SY[i]
		rs = SY[-1]-ls
		dl = y*i-ls
		dr = rs-y*(N-i)
		next d<dl+dr
	}-1
	l = (-10**9..Y[IY]).bsearch{|y|
		i = Y.bsearch_index{ y<=_1 }||N
		# 左に i 個 / 右に N-i 個
		ls = SY[i]
		rs = SY[-1]-ls
		dl = y*i-ls
		dr = rs-y*(N-i)
		next d>=dl+dr
	}||Y[IY]
	next r-l+1
}

a = 0
i = IX
(X[i]..).each{|x|
	i += 1 while X[i]&&X[i]<=x
	# 左に i 個 / 右に N-i 個
	raise if i<0 || N-i<0
	ls = SX[i]
	rs = SX[-1]-ls
	dl = x*i-ls
	dr = rs-x*(N-i)
	raise if dl<0 || dr<0
	break if D<dl+dr
	a += CY[D-dl-dr]
}
i = IX
(X[i]-1).downto(-10**9){|x|
	i -= 1 while 0<=i&&x<=X[i]
	# 左に i+1 個 / 右に N-(i+1) 個
	raise if i+1<0 || N-i-1<0
	ls = SX[i+1]
	rs = SX[-1]-ls
	dl = x*(i+1)-ls
	dr = rs-x*(N-i-1)
#p [X,x,d,-dl,-dr,i+1,N-i-1] if dl<0 || dr<0
	raise if dl<0 || dr<0
	break if D<dl+dr
	a += CY[D-dl-dr]
}

p a

Submission Info

Submission Time
Task E - Manhattan Multifocal Ellipse
User ds14050
Language Ruby (ruby 3.2.2)
Score 0
Code Size 1309 Byte
Status WA
Exec Time 2208 ms
Memory 43768 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 475
Status
AC × 3
AC × 23
WA × 1
TLE × 5
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.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_handmade_01.txt, 02_handmade_02.txt, 02_handmade_03.txt, 02_handmade_04.txt, 02_handmade_05.txt, 02_handmade_06.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 45 ms 17344 KiB
00_sample_02.txt AC 43 ms 17024 KiB
00_sample_03.txt AC 45 ms 17448 KiB
01_random_01.txt TLE 2208 ms 17544 KiB
01_random_02.txt AC 792 ms 17652 KiB
01_random_03.txt AC 1591 ms 17564 KiB
01_random_04.txt AC 493 ms 17592 KiB
01_random_05.txt AC 568 ms 17648 KiB
01_random_06.txt AC 284 ms 43576 KiB
01_random_07.txt AC 283 ms 43768 KiB
01_random_08.txt WA 119 ms 17536 KiB
01_random_09.txt AC 78 ms 17544 KiB
01_random_10.txt AC 54 ms 17528 KiB
01_random_11.txt AC 85 ms 17588 KiB
01_random_12.txt AC 62 ms 17468 KiB
01_random_13.txt AC 142 ms 17648 KiB
01_random_14.txt AC 44 ms 17328 KiB
01_random_15.txt AC 82 ms 17632 KiB
01_random_16.txt AC 56 ms 17528 KiB
01_random_17.txt AC 43 ms 17316 KiB
01_random_18.txt AC 164 ms 17568 KiB
01_random_19.txt AC 80 ms 17516 KiB
01_random_20.txt AC 83 ms 17520 KiB
02_handmade_01.txt AC 82 ms 17620 KiB
02_handmade_02.txt AC 45 ms 17504 KiB
02_handmade_03.txt TLE 2208 ms 17524 KiB
02_handmade_04.txt TLE 2208 ms 17456 KiB
02_handmade_05.txt TLE 2208 ms 17564 KiB
02_handmade_06.txt TLE 2208 ms 17580 KiB