Submission #1935144


Source Code Expand

Copy
lines = $stdin.read
array = lines.split("\n")

R,G,B = array[0].split(" ").map(&:to_i)
INF   = 1 << 25
dp    = Array.new(1000).map{ Array.new(1000, 0) }
total = R+G+B

def cost(pos, remain)
  if remain >= G+B
    (400-pos).abs
  elsif remain >= B
    (500-pos).abs
  else
    (600-pos).abs
  end
end

for i in 0...1000
  for j in 0...1000
    dp[i][j] = INF
  end
end
for i in 0...1000
  dp[i][total] = 0
end

for i in 1...1000
  for j in 0...total
    dp[i][j] = [ dp[i-1][j], dp[i-1][j+1] + cost(i,j) ].min
  end
  # p dp[i].take(total)
end

ans = INF
for i in 0...1000
  ans = [ans, dp[i][0]].min
end

puts ans

Submission Info

Submission Time
Task D - マーブル
User hiroyuking
Language Ruby (2.3.3)
Score 100
Code Size 652 Byte
Status
Exec Time 614 ms
Memory 11900 KB

Test Cases

Set Name Score / Max Score Test Cases
sub1 10 / 10 sample_01_ABC.txt, test_ABC_01.txt, test_ABC_02.txt, test_ABC_03.txt, test_ABC_04.txt, test_ABC_05.txt, test_ABC_06.txt, test_ABC_07.txt, test_ABC_08.txt, test_ABC_09.txt, test_ABC_10.txt, test_ABC_11.txt, test_ABC_12.txt, test_ABC_13.txt, test_ABC_14.txt, test_ABC_15.txt, test_ABC_16.txt, test_ABC_17.txt, test_ABC_18.txt, test_ABC_19.txt, test_ABC_20.txt, test_ABC_21.txt, test_ABC_22.txt, test_ABC_23.txt, test_ABC_24.txt, test_ABC_25.txt, test_ABC_26.txt, test_ABC_27.txt, test_ABC_28.txt
sub2 30 / 30 sample_01_ABC.txt, sample_02_BC.txt, test_ABC_01.txt, test_ABC_02.txt, test_ABC_03.txt, test_ABC_04.txt, test_ABC_05.txt, test_ABC_06.txt, test_ABC_07.txt, test_ABC_08.txt, test_ABC_09.txt, test_ABC_10.txt, test_ABC_11.txt, test_ABC_12.txt, test_ABC_13.txt, test_ABC_14.txt, test_ABC_15.txt, test_ABC_16.txt, test_ABC_17.txt, test_ABC_18.txt, test_ABC_19.txt, test_ABC_20.txt, test_ABC_21.txt, test_ABC_22.txt, test_ABC_23.txt, test_ABC_24.txt, test_ABC_25.txt, test_ABC_26.txt, test_ABC_27.txt, test_ABC_28.txt, test_BC_29.txt, test_BC_30.txt, test_BC_31.txt, test_BC_32.txt, test_BC_33.txt, test_BC_34.txt, test_BC_35.txt, test_BC_36.txt, test_BC_37.txt, test_BC_38.txt, test_BC_39.txt, test_BC_40.txt, test_BC_41.txt, test_BC_42.txt, test_BC_43.txt, test_BC_44.txt, test_BC_45.txt, test_BC_46.txt, test_BC_47.txt, test_BC_48.txt, test_BC_49.txt, test_BC_50.txt, test_BC_51.txt, test_BC_52.txt, test_BC_53.txt, test_BC_54.txt, test_BC_55.txt
All 60 / 60 sample_01_ABC.txt, sample_02_BC.txt, sample_03_C.txt, test_ABC_01.txt, test_ABC_02.txt, test_ABC_03.txt, test_ABC_04.txt, test_ABC_05.txt, test_ABC_06.txt, test_ABC_07.txt, test_ABC_08.txt, test_ABC_09.txt, test_ABC_10.txt, test_ABC_11.txt, test_ABC_12.txt, test_ABC_13.txt, test_ABC_14.txt, test_ABC_15.txt, test_ABC_16.txt, test_ABC_17.txt, test_ABC_18.txt, test_ABC_19.txt, test_ABC_20.txt, test_ABC_21.txt, test_ABC_22.txt, test_ABC_23.txt, test_ABC_24.txt, test_ABC_25.txt, test_ABC_26.txt, test_ABC_27.txt, test_ABC_28.txt, test_BC_29.txt, test_BC_30.txt, test_BC_31.txt, test_BC_32.txt, test_BC_33.txt, test_BC_34.txt, test_BC_35.txt, test_BC_36.txt, test_BC_37.txt, test_BC_38.txt, test_BC_39.txt, test_BC_40.txt, test_BC_41.txt, test_BC_42.txt, test_BC_43.txt, test_BC_44.txt, test_BC_45.txt, test_BC_46.txt, test_BC_47.txt, test_BC_48.txt, test_BC_49.txt, test_BC_50.txt, test_BC_51.txt, test_BC_52.txt, test_BC_53.txt, test_BC_54.txt, test_BC_55.txt, test_C_56.txt, test_C_57.txt, test_C_58.txt, test_C_59.txt, test_C_60.txt, test_C_61.txt, test_C_62.txt, test_C_63.txt, test_C_64.txt, test_C_65.txt, test_C_66.txt, test_C_67.txt, test_C_68.txt, test_C_69.txt, test_C_70.txt, test_C_71.txt, test_C_72.txt, test_C_73.txt, test_C_74.txt, test_C_75.txt, test_C_76.txt, test_C_77.txt, test_C_78.txt, test_C_79.txt, test_C_80.txt, test_C_81.txt, test_C_82.txt
Case Name Status Exec Time Memory
sample_01_ABC.txt 113 ms 9852 KB
sample_02_BC.txt 139 ms 9980 KB
sample_03_C.txt 529 ms 9980 KB
test_ABC_01.txt 112 ms 9980 KB
test_ABC_02.txt 114 ms 9852 KB
test_ABC_03.txt 112 ms 9980 KB
test_ABC_04.txt 114 ms 9980 KB
test_ABC_05.txt 111 ms 9980 KB
test_ABC_06.txt 113 ms 9980 KB
test_ABC_07.txt 116 ms 9980 KB
test_ABC_08.txt 114 ms 9980 KB
test_ABC_09.txt 113 ms 11900 KB
test_ABC_10.txt 112 ms 9980 KB
test_ABC_11.txt 115 ms 9980 KB
test_ABC_12.txt 112 ms 9980 KB
test_ABC_13.txt 115 ms 9980 KB
test_ABC_14.txt 116 ms 9980 KB
test_ABC_15.txt 113 ms 9980 KB
test_ABC_16.txt 114 ms 9980 KB
test_ABC_17.txt 113 ms 9980 KB
test_ABC_18.txt 114 ms 9980 KB
test_ABC_19.txt 114 ms 9980 KB
test_ABC_20.txt 113 ms 9980 KB
test_ABC_21.txt 104 ms 9852 KB
test_ABC_22.txt 112 ms 9980 KB
test_ABC_23.txt 111 ms 9980 KB
test_ABC_24.txt 115 ms 9980 KB
test_ABC_25.txt 114 ms 9980 KB
test_ABC_26.txt 115 ms 9980 KB
test_ABC_27.txt 114 ms 9980 KB
test_ABC_28.txt 117 ms 9980 KB
test_BC_29.txt 127 ms 9980 KB
test_BC_30.txt 128 ms 9980 KB
test_BC_31.txt 138 ms 9980 KB
test_BC_32.txt 142 ms 9980 KB
test_BC_33.txt 152 ms 9852 KB
test_BC_34.txt 154 ms 9980 KB
test_BC_35.txt 134 ms 9980 KB
test_BC_36.txt 144 ms 9980 KB
test_BC_37.txt 142 ms 9980 KB
test_BC_38.txt 139 ms 9852 KB
test_BC_39.txt 136 ms 9980 KB
test_BC_40.txt 153 ms 9980 KB
test_BC_41.txt 152 ms 9980 KB
test_BC_42.txt 162 ms 9980 KB
test_BC_43.txt 139 ms 9980 KB
test_BC_44.txt 133 ms 9980 KB
test_BC_45.txt 135 ms 9980 KB
test_BC_46.txt 149 ms 9980 KB
test_BC_47.txt 140 ms 9980 KB
test_BC_48.txt 159 ms 9980 KB
test_BC_49.txt 154 ms 9980 KB
test_BC_50.txt 155 ms 9852 KB
test_BC_51.txt 153 ms 9980 KB
test_BC_52.txt 131 ms 9980 KB
test_BC_53.txt 131 ms 9980 KB
test_BC_54.txt 132 ms 9852 KB
test_BC_55.txt 176 ms 9980 KB
test_C_56.txt 270 ms 9980 KB
test_C_57.txt 389 ms 9852 KB
test_C_58.txt 422 ms 9980 KB
test_C_59.txt 362 ms 9852 KB
test_C_60.txt 245 ms 9980 KB
test_C_61.txt 332 ms 9980 KB
test_C_62.txt 310 ms 9980 KB
test_C_63.txt 338 ms 9980 KB
test_C_64.txt 290 ms 9980 KB
test_C_65.txt 360 ms 9980 KB
test_C_66.txt 348 ms 9980 KB
test_C_67.txt 389 ms 9980 KB
test_C_68.txt 268 ms 9980 KB
test_C_69.txt 274 ms 9980 KB
test_C_70.txt 307 ms 9980 KB
test_C_71.txt 398 ms 11900 KB
test_C_72.txt 510 ms 9980 KB
test_C_73.txt 421 ms 9980 KB
test_C_74.txt 409 ms 9980 KB
test_C_75.txt 360 ms 9980 KB
test_C_76.txt 448 ms 9980 KB
test_C_77.txt 445 ms 9980 KB
test_C_78.txt 448 ms 9980 KB
test_C_79.txt 278 ms 9980 KB
test_C_80.txt 284 ms 9980 KB
test_C_81.txt 275 ms 9980 KB
test_C_82.txt 614 ms 9980 KB