Submission #35161366
Source Code Expand
(N,M),X,Y,*EZ = $<.map{|ln| ln.split.map(&:to_i) }
EZ.map!{|a,b,z| [a-1,b-1,z] }
XI = X.index Xmin = X.min
YI = Y.index Ymin = Y.min
EX = X.map.with_index{|x,i| [XI,i,x] }
EY = Y.map.with_index{|y,i| [YI,i,y] }
EX.delete_at XI
EY.delete_at YI
F = lambda{|g,a|
g[a]<0 ? a : g[a] = F[g,g[a]]
}
U = lambda{|g,a,b,z|
a,b = F[g,a],F[g,b]
next 0 if a==b
g[a] += g[b]
g[b] = a
next z
}
C4 = 0,Xmin,Ymin,Xmin+Ymin
E4 = EZ,EZ+EX,EZ+EY,EZ+EY+EX
G4 = 4.times.map{ [-1]*N }
p C4.zip(E4,G4).map{|c,e,g|
e.sort_by{_3}.each{|a,b,z|
c += U[g,a,b,z]
}
next -g[F[g,0]]<N ? 1.0/0 : c
}.min
Submission Info
Submission Time
2022-09-25 20:28:27+0900
Task
F - Transportation
User
ds14050
Language
Ruby (2.7.1)
Score
500
Code Size
613 Byte
Status
AC
Exec Time
1956 ms
Memory
96968 KiB
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
500 / 500
Status
Set Name
Test Cases
Sample
example_00.txt, example_01.txt, example_02.txt
All
example_00.txt, example_01.txt, example_02.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt
Case Name
Status
Exec Time
Memory
example_00.txt
AC
54 ms
14092 KiB
example_01.txt
AC
57 ms
14224 KiB
example_02.txt
AC
56 ms
14176 KiB
hand_00.txt
AC
1274 ms
94920 KiB
hand_01.txt
AC
1220 ms
96556 KiB
hand_02.txt
AC
1216 ms
94656 KiB
hand_03.txt
AC
521 ms
79852 KiB
hand_04.txt
AC
1409 ms
95944 KiB
hand_05.txt
AC
1414 ms
96480 KiB
hand_06.txt
AC
1286 ms
92024 KiB
hand_07.txt
AC
1334 ms
92688 KiB
random_00.txt
AC
1814 ms
95756 KiB
random_01.txt
AC
923 ms
84568 KiB
random_02.txt
AC
1773 ms
95632 KiB
random_03.txt
AC
902 ms
84172 KiB
random_04.txt
AC
1803 ms
95640 KiB
random_05.txt
AC
832 ms
84748 KiB
random_06.txt
AC
1791 ms
96932 KiB
random_07.txt
AC
876 ms
83912 KiB
random_08.txt
AC
1524 ms
96912 KiB
random_09.txt
AC
919 ms
75312 KiB
random_10.txt
AC
1902 ms
96444 KiB
random_11.txt
AC
865 ms
83424 KiB
random_12.txt
AC
1956 ms
96236 KiB
random_13.txt
AC
952 ms
84104 KiB
random_14.txt
AC
1806 ms
96528 KiB
random_15.txt
AC
883 ms
87904 KiB
random_16.txt
AC
1885 ms
96904 KiB
random_17.txt
AC
890 ms
85964 KiB
random_18.txt
AC
1912 ms
96552 KiB
random_19.txt
AC
915 ms
83688 KiB
random_20.txt
AC
1780 ms
96444 KiB
random_21.txt
AC
919 ms
83600 KiB
random_22.txt
AC
1938 ms
96464 KiB
random_23.txt
AC
857 ms
84192 KiB
random_24.txt
AC
1922 ms
96700 KiB
random_25.txt
AC
911 ms
83804 KiB
random_26.txt
AC
1598 ms
96872 KiB
random_27.txt
AC
919 ms
84460 KiB
random_28.txt
AC
1926 ms
96968 KiB
random_29.txt
AC
936 ms
85268 KiB