Submission #3204358


Source Code Expand

Copy
N, X, *XS = $stdin.read.split.map(&:to_i)
def solve(disp)
  order = (0...N).to_a.reverse
  ans = 0; n_garbages = 0; pos = 0
  order.zip(disp) do |(id, d)|
    ans += (n_garbages + 1)**2 * (XS[id] - pos).abs; pos = XS[id]
    ans += X; n_garbages += 1
    if d
      ans += (n_garbages + 1)**2 * pos; pos = 0
      ans += X; n_garbages = 0
    end
  end
  ans
end
p [
  solve([true] * N),
  solve([false] * (N-1) + [true]),
  solve((N-1).times.map(&:odd?) + [true]),
  solve((N-1).times.map(&:even?) + [true]),
].min

Submission Info

Submission Time
Task B - Garbage Collector
User yhara
Language Ruby (2.3.3)
Score 0
Code Size 538 Byte
Status
Exec Time 451 ms
Memory 32580 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
Subtask1 0 / 400 sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, stest_01.txt, stest_02.txt, stest_03.txt, stest_04.txt, stest_05.txt, stest_06.txt, stest_07.txt, stest_08.txt, stest_09.txt, stest_10.txt, stest_11.txt, stest_12.txt
All 0 / 300 sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, stest_01.txt, stest_02.txt, stest_03.txt, stest_04.txt, stest_05.txt, stest_06.txt, stest_07.txt, stest_08.txt, stest_09.txt, stest_10.txt, stest_11.txt, stest_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt
Case Name Status Exec Time Memory
sample_01.txt 7 ms 1788 KB
sample_02.txt 7 ms 1788 KB
sample_03.txt 7 ms 1788 KB
sample_04.txt 7 ms 1788 KB
stest_01.txt 12 ms 2044 KB
stest_02.txt 12 ms 2044 KB
stest_03.txt 7 ms 1788 KB
stest_04.txt 7 ms 1788 KB
stest_05.txt 11 ms 2044 KB
stest_06.txt 10 ms 1916 KB
stest_07.txt 12 ms 2044 KB
stest_08.txt 12 ms 2044 KB
stest_09.txt 9 ms 1916 KB
stest_10.txt 12 ms 2044 KB
stest_11.txt 12 ms 2044 KB
stest_12.txt 8 ms 1916 KB
test_13.txt 445 ms 32452 KB
test_14.txt 451 ms 32508 KB
test_15.txt 92 ms 10116 KB
test_16.txt 436 ms 32240 KB
test_17.txt 436 ms 31756 KB
test_18.txt 70 ms 6264 KB
test_19.txt 440 ms 32124 KB
test_20.txt 426 ms 32580 KB
test_21.txt 432 ms 32124 KB
test_22.txt 427 ms 32440 KB
test_23.txt 420 ms 32184 KB
test_24.txt 435 ms 31756 KB
test_25.txt 234 ms 18860 KB
test_26.txt 436 ms 32524 KB
test_27.txt 437 ms 32052 KB
test_28.txt 338 ms 30004 KB