結果
| 問題 |
No.1122 Plane Tickets
|
| コンテスト | |
| ユーザー |
tomerun
|
| 提出日時 | 2020-07-22 22:52:54 |
| 言語 | Crystal (1.14.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,682 bytes |
| コンパイル時間 | 16,043 ms |
| コンパイル使用メモリ | 318,700 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-30 20:43:34 |
| 合計ジャッジ時間 | 17,652 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 6 WA * 1 RE * 48 |
ソースコード
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
tomerun