結果
| 問題 |
No.497 入れ子の箱
|
| コンテスト | |
| ユーザー |
rickytheta
|
| 提出日時 | 2017-03-24 22:58:48 |
| 言語 | Ruby (3.4.1) |
| 結果 |
AC
|
| 実行時間 | 239 ms / 5,000 ms |
| コード長 | 808 bytes |
| コンパイル時間 | 41 ms |
| コンパイル使用メモリ | 7,424 KB |
| 実行使用メモリ | 12,672 KB |
| 最終ジャッジ日時 | 2024-07-05 23:02:48 |
| 合計ジャッジ時間 | 6,512 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 |
コンパイルメッセージ
Syntax OK
ソースコード
n = gets.chomp.to_i
boxes = []
for i in 0...n
a = gets.chomp.split.map(&:to_i)
boxes.push a
end
boxes.sort!{|a,b| a[0]*a[1]*a[2] <=> b[0]*b[1]*b[2]}
dp = []
for i in 0...n
dp[i] = -1
end
ans = 0
def wide(a,b)
return true if a[0]<b[0] && a[1]<b[1] && a[2]<b[2]
return true if a[0]<b[0] && a[2]<b[1] && a[1]<b[2]
return true if a[1]<b[0] && a[0]<b[1] && a[2]<b[2]
return true if a[1]<b[0] && a[2]<b[1] && a[0]<b[2]
return true if a[2]<b[0] && a[0]<b[1] && a[1]<b[2]
return true if a[2]<b[0] && a[1]<b[1] && a[0]<b[2]
return false
end
for i in 0...n
box = boxes[n-1-i]
mx = 0
# search wider box
for j in n-i...n
if wide(box, boxes[j])
if dp[j] > mx
mx = dp[j]
end
end
end
dp[n-1-i] = mx+1
if dp[n-1-i] > ans
ans = dp[n-1-i]
end
end
puts ans
rickytheta