結果

問題 No.1122 Plane Tickets
ユーザー tomeruntomerun
提出日時 2020-07-22 22:52:54
言語 Crystal
(1.11.2)
結果
WA  
実行時間 -
コード長 1,682 bytes
コンパイル時間 21,450 ms
コンパイル使用メモリ 283,056 KB
実行使用メモリ 4,856 KB
最終ジャッジ日時 2023-09-13 11:24:00
合計ジャッジ時間 22,932 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,664 KB
testcase_01 AC 3 ms
4,564 KB
testcase_02 AC 3 ms
4,700 KB
testcase_03 AC 3 ms
4,592 KB
testcase_04 AC 3 ms
4,596 KB
testcase_05 AC 3 ms
4,696 KB
testcase_06 AC 3 ms
4,632 KB
testcase_07 WA -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 AC 3 ms
4,708 KB
testcase_51 RE -
testcase_52 RE -
testcase_53 RE -
testcase_54 RE -
testcase_55 RE -
testcase_56 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

vs = read_line.split.map(&.to_i64)
es = [] of Array(Float64)
5.times do |i|
  e = [0.0] * 6
  e[5] = vs[i].to_f64
  e[i - 1] = e[i] = e[(i + 1) % 5] = 1i64
  es << e
  e = [0.0] * 6
  e[i] = 1
  es << e
end
ans = 0i64
(1 << 10).times do |i|
  next if i.popcount != 5
  mat = [] of Array(Float64)
  10.times do |j|
    if (i & (1 << j)) != 0
      mat << es[j].clone
    end
  end
  ans = {ans, solve(vs, mat)}.max
end
puts ans

def solve(vs, mat)
  used = Array.new(5, false)
  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 0i64 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
  end
  5.times do |i|
    return 0i64 if mat[i][5] < -1e-8
  end
  cs = mat.map { |row| row[5].to_i64 }
  ret = 0i64
  {0, cs[0] - 1}.max.upto(cs[0]) do |c0|
    {0, cs[1] - 1}.max.upto(cs[1]) do |c1|
      {0, cs[2] - 1}.max.upto(cs[2]) do |c2|
        {0, cs[3] - 1}.max.upto(cs[3]) do |c3|
          {0, cs[4] - 1}.max.upto(cs[4]) 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
0