結果

問題 No.1122 Plane Tickets
ユーザー tomeruntomerun
提出日時 2020-07-22 23:13:13
言語 Ruby
(3.3.0)
結果
AC  
実行時間 110 ms / 1,000 ms
コード長 1,696 bytes
コンパイル時間 62 ms
コンパイル使用メモリ 11,336 KB
実行使用メモリ 15,392 KB
最終ジャッジ日時 2023-09-05 22:15:26
合計ジャッジ時間 7,859 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
15,392 KB
testcase_01 AC 94 ms
15,164 KB
testcase_02 AC 96 ms
15,124 KB
testcase_03 AC 97 ms
15,352 KB
testcase_04 AC 98 ms
15,200 KB
testcase_05 AC 97 ms
15,112 KB
testcase_06 AC 98 ms
15,192 KB
testcase_07 AC 99 ms
15,120 KB
testcase_08 AC 102 ms
15,336 KB
testcase_09 AC 99 ms
15,204 KB
testcase_10 AC 97 ms
15,376 KB
testcase_11 AC 96 ms
15,312 KB
testcase_12 AC 96 ms
15,056 KB
testcase_13 AC 102 ms
15,084 KB
testcase_14 AC 100 ms
15,324 KB
testcase_15 AC 96 ms
15,144 KB
testcase_16 AC 101 ms
15,196 KB
testcase_17 AC 100 ms
15,316 KB
testcase_18 AC 101 ms
15,292 KB
testcase_19 AC 102 ms
15,076 KB
testcase_20 AC 104 ms
15,308 KB
testcase_21 AC 96 ms
15,336 KB
testcase_22 AC 99 ms
15,116 KB
testcase_23 AC 98 ms
15,080 KB
testcase_24 AC 105 ms
15,112 KB
testcase_25 AC 100 ms
15,116 KB
testcase_26 AC 96 ms
15,140 KB
testcase_27 AC 100 ms
15,324 KB
testcase_28 AC 102 ms
15,296 KB
testcase_29 AC 98 ms
15,316 KB
testcase_30 AC 99 ms
15,048 KB
testcase_31 AC 103 ms
15,276 KB
testcase_32 AC 110 ms
15,188 KB
testcase_33 AC 109 ms
15,120 KB
testcase_34 AC 95 ms
15,292 KB
testcase_35 AC 95 ms
15,056 KB
testcase_36 AC 92 ms
15,108 KB
testcase_37 AC 94 ms
15,264 KB
testcase_38 AC 95 ms
15,364 KB
testcase_39 AC 96 ms
15,172 KB
testcase_40 AC 93 ms
15,296 KB
testcase_41 AC 98 ms
15,272 KB
testcase_42 AC 94 ms
15,100 KB
testcase_43 AC 93 ms
15,316 KB
testcase_44 AC 94 ms
15,080 KB
testcase_45 AC 92 ms
15,372 KB
testcase_46 AC 92 ms
15,188 KB
testcase_47 AC 94 ms
15,108 KB
testcase_48 AC 93 ms
15,384 KB
testcase_49 AC 108 ms
15,092 KB
testcase_50 AC 94 ms
15,292 KB
testcase_51 AC 102 ms
15,312 KB
testcase_52 AC 104 ms
15,152 KB
testcase_53 AC 105 ms
15,364 KB
testcase_54 AC 105 ms
15,176 KB
testcase_55 AC 104 ms
15,316 KB
testcase_56 AC 105 ms
15,176 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def solve(vs, mat)
  used = Array.new(5, false)
  ps = []
  5.times do |i|
    pivot = -1
    5.times do |j|
      next if used[j]
      next if mat[j][i].abs < 1e-8
      if pivot == -1 || mat[pivot][i].abs > mat[j][i].abs
        pivot = j
      end
    end
    return 0 if pivot == -1
    (i + 1).upto(5) do |j|
      mat[pivot][j] /= mat[pivot][i]
    end
    mat[pivot][i] = 1.0
    5.times do |j|
      next if j == pivot
      next if mat[j][i] == 0
      (i + 1).upto(5) do |k|
        mat[j][k] -= mat[j][i] * mat[pivot][k]
      end
      mat[j][i] = 0
    end
    used[pivot] = true
    ps << pivot
  end
  5.times do |i|
    return 0 if mat[i][5] < -1e-8
  end
  cs = 5.times.map { |i| mat[ps[i]][5].to_i }
  ret = 0
  [0, cs[0] - 2].max.upto(cs[0] + 2) do |c0|
    [0, cs[1] - 2].max.upto(cs[1] + 2) do |c1|
      [0, cs[2] - 2].max.upto(cs[2] + 2) do |c2|
        [0, cs[3] - 2].max.upto(cs[3] + 2) do |c3|
          [0, cs[4] - 2].max.upto(cs[4] + 2) do |c4|
            next if c4 + c0 + c1 > vs[0]
            next if c0 + c1 + c2 > vs[1]
            next if c1 + c2 + c3 > vs[2]
            next if c2 + c3 + c4 > vs[3]
            next if c3 + c4 + c0 > vs[4]
            ret = [ret, c0 + c1 + c2 + c3 + c4].max
          end
        end
      end
    end
  end
  return ret
end

vs = readline.split.map(&:to_i)
es = []
5.times do |i|
  e = [0.0] * 6
  e[5] = vs[i].to_f
  e[(i + 4) % 5] = e[i] = e[(i + 1) % 5] = 1
  es << e
  e = [0.0] * 6
  e[i] = 1
  es << e
end
ans = 0
(1 << 10).times do |i|
  next if i.to_s(2).count("1") != 5
  mat = []
  10.times do |j|
    if (i & (1 << j)) != 0
      mat << es[j].clone
    end
  end
  ans = [ans, solve(vs, mat)].max
end
puts ans

0