Submission #65046061


Source Code Expand

(N,M),*A = $<.map{|ln| ln.split.map(&:to_i) }
[*0...N].repeated_permutation(2){|i,j|
	k = N+N-2-i-j
	A[i][j] = A[i][j]*10.pow(k,M)%M
}
B = A.map{|r| r.map{ [] } }
B[0][0]<<0
B[-1][-1]<<0
(N-1).times{|i|
	a0 = A[i]
	r0,r1 = B[i,2]
	(N-1-i).times{|j|
		a = a0[j]
		r0a = r0[j].map{_1+a}
		r1[j].concat r0a
		r0[j+1].concat r0a
	}
}
(N-1).times{|i|
	a9 = A[~i]
	r8,r9 = B[N-2-i,2]
	(N-1-i).times{|j|
		a = a9[~j]
		r9a = r9[~j].map{_1+a}
		r8[~j].concat r9a
		r9[~j-1].concat r9a
	}
}
p N.times.map{|i|
	a,as = A[i][~i],B[i][~i]
	bs = as.pop as.size/2
	as.map!{ (_1+a)%M }.sort!
	bs.map!{ _1%M }.sort!
	[(as[-1]+bs[-1])%M,as.reverse.map{|a|
		bs.shift while bs[1]&&a+bs[1]<M
		(a+bs[0])%M
	}.max].max
}.max

Submission Info

Submission Time
Task F - Path to Integer
User ds14050
Language Ruby (ruby 3.2.2)
Score 525
Code Size 742 Byte
Status AC
Exec Time 258 ms
Memory 60168 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 525 / 525
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_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 01_handmade_04.txt, 01_handmade_05.txt, 01_handmade_06.txt, 01_handmade_07.txt, 01_handmade_08.txt, 01_handmade_09.txt, 01_handmade_10.txt, 01_handmade_11.txt, 01_handmade_12.txt, 01_handmade_13.txt, 01_handmade_14.txt, 01_handmade_15.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt, 02_random_18.txt, 02_random_19.txt, 02_random_20.txt, 02_random_21.txt, 02_random_22.txt, 02_random_23.txt, 02_random_24.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 134 ms 17152 KiB
00_sample_01.txt AC 44 ms 17224 KiB
00_sample_02.txt AC 45 ms 17108 KiB
01_handmade_00.txt AC 44 ms 17156 KiB
01_handmade_01.txt AC 45 ms 17184 KiB
01_handmade_02.txt AC 45 ms 17296 KiB
01_handmade_03.txt AC 44 ms 17236 KiB
01_handmade_04.txt AC 46 ms 17468 KiB
01_handmade_05.txt AC 52 ms 18684 KiB
01_handmade_06.txt AC 217 ms 54456 KiB
01_handmade_07.txt AC 188 ms 54796 KiB
01_handmade_08.txt AC 191 ms 54804 KiB
01_handmade_09.txt AC 182 ms 54636 KiB
01_handmade_10.txt AC 44 ms 17120 KiB
01_handmade_11.txt AC 48 ms 17648 KiB
01_handmade_12.txt AC 248 ms 54924 KiB
01_handmade_13.txt AC 249 ms 54668 KiB
01_handmade_14.txt AC 193 ms 55068 KiB
01_handmade_15.txt AC 195 ms 54228 KiB
02_random_00.txt AC 44 ms 17224 KiB
02_random_01.txt AC 47 ms 17544 KiB
02_random_02.txt AC 46 ms 17420 KiB
02_random_03.txt AC 47 ms 17596 KiB
02_random_04.txt AC 44 ms 17096 KiB
02_random_05.txt AC 46 ms 17472 KiB
02_random_06.txt AC 45 ms 17136 KiB
02_random_07.txt AC 46 ms 17328 KiB
02_random_08.txt AC 70 ms 22936 KiB
02_random_09.txt AC 46 ms 17468 KiB
02_random_10.txt AC 251 ms 54804 KiB
02_random_11.txt AC 257 ms 54824 KiB
02_random_12.txt AC 253 ms 54844 KiB
02_random_13.txt AC 257 ms 54580 KiB
02_random_14.txt AC 255 ms 54740 KiB
02_random_15.txt AC 253 ms 60168 KiB
02_random_16.txt AC 257 ms 54856 KiB
02_random_17.txt AC 258 ms 54944 KiB
02_random_18.txt AC 253 ms 54728 KiB
02_random_19.txt AC 250 ms 54688 KiB
02_random_20.txt AC 254 ms 55000 KiB
02_random_21.txt AC 254 ms 54676 KiB
02_random_22.txt AC 253 ms 54536 KiB
02_random_23.txt AC 256 ms 54748 KiB
02_random_24.txt AC 253 ms 54696 KiB