結果

問題 No.497 入れ子の箱
ユーザー rickythetarickytheta
提出日時 2017-03-24 22:58:48
言語 Ruby
(3.3.0)
結果
AC  
実行時間 257 ms / 5,000 ms
コード長 808 bytes
コンパイル時間 473 ms
コンパイル使用メモリ 11,256 KB
実行使用メモリ 15,444 KB
最終ジャッジ日時 2023-09-20 02:42:22
合計ジャッジ時間 8,338 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
15,156 KB
testcase_01 AC 80 ms
15,304 KB
testcase_02 AC 79 ms
15,252 KB
testcase_03 AC 170 ms
15,128 KB
testcase_04 AC 176 ms
15,248 KB
testcase_05 AC 172 ms
15,292 KB
testcase_06 AC 180 ms
15,300 KB
testcase_07 AC 194 ms
15,312 KB
testcase_08 AC 195 ms
15,292 KB
testcase_09 AC 194 ms
15,268 KB
testcase_10 AC 194 ms
15,308 KB
testcase_11 AC 194 ms
15,180 KB
testcase_12 AC 238 ms
15,184 KB
testcase_13 AC 243 ms
15,172 KB
testcase_14 AC 248 ms
15,292 KB
testcase_15 AC 242 ms
15,444 KB
testcase_16 AC 240 ms
15,336 KB
testcase_17 AC 242 ms
15,060 KB
testcase_18 AC 171 ms
15,408 KB
testcase_19 AC 171 ms
15,240 KB
testcase_20 AC 172 ms
15,324 KB
testcase_21 AC 179 ms
15,328 KB
testcase_22 AC 172 ms
15,272 KB
testcase_23 AC 214 ms
15,160 KB
testcase_24 AC 215 ms
15,300 KB
testcase_25 AC 82 ms
15,164 KB
testcase_26 AC 81 ms
15,268 KB
testcase_27 AC 219 ms
15,160 KB
testcase_28 AC 223 ms
15,240 KB
testcase_29 AC 220 ms
15,276 KB
testcase_30 AC 257 ms
15,308 KB
testcase_31 AC 254 ms
15,436 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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
0