結果

問題 No.497 入れ子の箱
ユーザー mkawa2mkawa2
提出日時 2020-05-21 14:27:04
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 618 ms / 5,000 ms
コード長 1,828 bytes
コンパイル時間 136 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 19,712 KB
最終ジャッジ日時 2024-04-09 23:22:51
合計ジャッジ時間 14,119 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
11,008 KB
testcase_01 AC 30 ms
11,008 KB
testcase_02 AC 29 ms
11,008 KB
testcase_03 AC 615 ms
19,456 KB
testcase_04 AC 611 ms
19,584 KB
testcase_05 AC 599 ms
19,584 KB
testcase_06 AC 597 ms
19,584 KB
testcase_07 AC 594 ms
19,584 KB
testcase_08 AC 599 ms
19,712 KB
testcase_09 AC 604 ms
19,584 KB
testcase_10 AC 618 ms
19,584 KB
testcase_11 AC 607 ms
19,584 KB
testcase_12 AC 401 ms
19,456 KB
testcase_13 AC 405 ms
19,584 KB
testcase_14 AC 405 ms
19,456 KB
testcase_15 AC 407 ms
19,456 KB
testcase_16 AC 410 ms
19,584 KB
testcase_17 AC 391 ms
19,456 KB
testcase_18 AC 594 ms
19,584 KB
testcase_19 AC 601 ms
19,456 KB
testcase_20 AC 598 ms
19,584 KB
testcase_21 AC 613 ms
19,584 KB
testcase_22 AC 614 ms
19,456 KB
testcase_23 AC 33 ms
11,264 KB
testcase_24 AC 34 ms
11,392 KB
testcase_25 AC 28 ms
11,136 KB
testcase_26 AC 28 ms
11,008 KB
testcase_27 AC 484 ms
19,456 KB
testcase_28 AC 492 ms
19,456 KB
testcase_29 AC 481 ms
19,456 KB
testcase_30 AC 64 ms
19,584 KB
testcase_31 AC 67 ms
19,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from operator import itemgetter
from itertools import *
from bisect import *
from collections import *
from heapq import *
import sys

sys.setrecursionlimit(10 ** 6)

def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def SI(): return sys.stdin.readline()[:-1]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
int1 = lambda x: int(x) - 1
def MI1(): return map(int1, sys.stdin.readline().split())
def LI1(): return list(map(int1, sys.stdin.readline().split()))
p2D = lambda x: print(*x, sep="\n")
dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]

class BitMax:
    def __init__(self, n=1005):
        self.inf=10**9
        self.n = n + 3
        self.table = [-self.inf] * (self.n + 1)

    def update(self, i, x):
        i += 1
        while i <= self.n:
            if x > self.table[i]: self.table[i] = x
            i += i & -i

    def max(self, i):
        i += 1
        res = -self.inf
        while i > 0:
            if self.table[i] > res: res = self.table[i]
            i -= i & -i
        return res

def main():
    n=II()
    zxy=defaultdict(list)
    yy=set()
    for xyz in LLI(n):
        x,y,z=sorted(xyz)
        yy.add(y)
        zxy[z].append((x,y))
    coy= {y: i+1 for i, y in enumerate(sorted(yy))}
    #print(zxy)

    dp=defaultdict(BitMax)
    ans=0
    for z,xy in sorted(zxy.items()):
        xyv=[]
        for x,y in xy:
            cy=coy[y]
            val=1
            for sx,bit in dp.items():
                if sx>=x:continue
                val=max(val,bit.max(cy-1)+1)
            ans=max(ans,val)
            xyv.append((x,cy,val))
        for x,cy,v in xyv:dp[x].update(cy,v)

    print(ans)

main()
0