結果
問題 | No.497 入れ子の箱 |
ユーザー |
![]() |
提出日時 | 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_iboxes = []for i in 0...na = gets.chomp.split.map(&:to_i)boxes.push aendboxes.sort!{|a,b| a[0]*a[1]*a[2] <=> b[0]*b[1]*b[2]}dp = []for i in 0...ndp[i] = -1endans = 0def 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 falseendfor i in 0...nbox = boxes[n-1-i]mx = 0# search wider boxfor j in n-i...nif wide(box, boxes[j])if dp[j] > mxmx = dp[j]endendenddp[n-1-i] = mx+1if dp[n-1-i] > ansans = dp[n-1-i]endendputs ans