結果

問題 No.497 入れ子の箱
ユーザー 0w1
提出日時 2017-04-10 18:37:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 105 ms / 5,000 ms
コード長 683 bytes
コンパイル時間 211 ms
コンパイル使用メモリ 82,364 KB
実行使用メモリ 77,312 KB
最終ジャッジ日時 2024-07-18 05:42:12
合計ジャッジ時間 4,023 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
from functools import cmp_to_key
N = int( input() )
X = []
Y = []
Z = []
for i in range( N ):
  x, y, z = sorted( list( map( int, input().split() ) ) )
  X.append( x )
  Y.append( y )
  Z.append( z )
ord = sorted( list( i for i in range( N ) ), key = cmp_to_key( lambda x, y: 0 if X[ x ] == X[ y ] else ( X[ x ] - X[ y ] ) // abs( X[ x ] - X[ y ] ) ) )
dp = defaultdict( int )
for i in range( N ):
  best = 0
  for j in range( i ):
    a, b = ord[ i ], ord[ j ]
    if X[ b ] < X[ a ] and Y[ b ] < Y[ a ] and Z[ b ] < Z[ a ]:
      best = max( best, dp[ j ] )
  dp[ i ] = best + 1
ans = 0
for key in dp:
  ans = max( ans, dp[ key ] )
print( ans )
0