結果

問題 No.497 入れ子の箱
ユーザー brthyyjpbrthyyjp
提出日時 2021-02-11 12:49:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 341 ms / 5,000 ms
コード長 1,370 bytes
コンパイル時間 1,264 ms
コンパイル使用メモリ 87,232 KB
実行使用メモリ 80,348 KB
最終ジャッジ日時 2023-09-25 01:55:34
合計ジャッジ時間 10,164 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
71,604 KB
testcase_01 AC 90 ms
71,740 KB
testcase_02 AC 92 ms
71,816 KB
testcase_03 AC 195 ms
78,536 KB
testcase_04 AC 309 ms
79,416 KB
testcase_05 AC 311 ms
79,348 KB
testcase_06 AC 312 ms
79,392 KB
testcase_07 AC 302 ms
79,568 KB
testcase_08 AC 303 ms
79,776 KB
testcase_09 AC 304 ms
79,512 KB
testcase_10 AC 303 ms
79,516 KB
testcase_11 AC 304 ms
79,496 KB
testcase_12 AC 301 ms
79,788 KB
testcase_13 AC 308 ms
80,260 KB
testcase_14 AC 311 ms
79,484 KB
testcase_15 AC 301 ms
79,888 KB
testcase_16 AC 305 ms
79,496 KB
testcase_17 AC 318 ms
79,724 KB
testcase_18 AC 341 ms
80,348 KB
testcase_19 AC 339 ms
79,912 KB
testcase_20 AC 332 ms
79,896 KB
testcase_21 AC 333 ms
79,424 KB
testcase_22 AC 334 ms
79,592 KB
testcase_23 AC 103 ms
77,024 KB
testcase_24 AC 99 ms
77,264 KB
testcase_25 AC 90 ms
71,596 KB
testcase_26 AC 93 ms
71,728 KB
testcase_27 AC 303 ms
79,780 KB
testcase_28 AC 309 ms
79,356 KB
testcase_29 AC 305 ms
79,600 KB
testcase_30 AC 207 ms
78,440 KB
testcase_31 AC 234 ms
79,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

def main():

    n = int(input())
    XYZ = []
    X = []
    for i in range(n):
        temp = list(map(int, input().split()))
        temp.sort()
        x, y, z = temp
        XYZ.append((x, y, z))
        X.append(x)

    X = sorted(list(set(X)))
    d = {}
    for i, x in enumerate(X):
        d[x] = i

    N = len(d)
    YZ = [[] for i in range(N)]
    for x, y, z in XYZ:
        YZ[d[x]].append((y, z))

    from collections import defaultdict
    dp = defaultdict(lambda:1)
    mod =10**9
    for y, z in YZ[0]:
        dp[y*mod+z] = 1
        dp[z*mod+y] = 1
    for i in range(1, N):
        nx = defaultdict(lambda:1)
        for k, v in dp.items():
            nx[k] = max(nx[k], v)
        for ny, nz in YZ[i]:
            nk = ny*mod+nz
            nx[nk] = 1
            nk = nz*mod+ny
            nx[nk] = 1
            for k, v in dp.items():
                y, z = divmod(k, mod)
                if y < ny and z < nz:
                    nk = ny*mod+nz
                    nx[nk] = max(nx[nk], dp[k]+1)
                if y < nz and z < ny:
                    nk = nz*mod+ny
                    nx[nk] = max(nx[nk], dp[k]+1)

        dp = nx
    ans = 1
    for k, v in dp.items():
        ans = max(ans, v)
    print(ans)

if __name__ == '__main__':
    main()
0