結果
問題 | No.497 入れ子の箱 |
ユーザー |
|
提出日時 | 2019-02-04 23:44:30 |
言語 | Nim (2.2.0) |
結果 |
AC
|
実行時間 | 311 ms / 5,000 ms |
コード長 | 1,428 bytes |
コンパイル時間 | 2,936 ms |
コンパイル使用メモリ | 64,176 KB |
実行使用メモリ | 19,968 KB |
最終ジャッジ日時 | 2024-07-01 11:23:36 |
合計ジャッジ時間 | 10,482 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 |
ソースコード
import sequtils,algorithmtemplate times*(n:int,body) = (for _ in 0..<n: body)template `max=`*(x,y) = x = max(x,y)template `min=`*(x,y) = x = min(x,y)proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "<stdio.h>" .}proc scan(): int =while true:let k = getchar_unlocked()if k < '0': returnresult = 10 * result + k.ord - '0'.ord# 隣接リスト([n->[m1,m2,m3], ... ])を トポロジカルソートproc topologicalSort(E:seq[seq[int]],deleteIsolated:bool = false) : seq[int] =var visited = newSeq[int](E.len)var answer = newSeq[int]()proc visit(src:int) =visited[src] += 1if visited[src] > 1: returnfor dst in E[src]: visit(dst)answer &= src # 葉から順に追加されるfor src in 0..<E.len: visit(src)if deleteIsolated: # 孤立点の除去return answer.filterIt(visited[it] > 1 or E[it].len > 0)return answerlet n = scan()let B = newSeqWith(n,(x:scan(),y:scan(),z:scan()))proc isSmall(a,b:tuple[x,y,z:int]): bool =var an = @[a.x,a.y,a.z].sorted(cmp)while true:if an[0] < b.x and an[1] < b.y and an[2] < b.z : return trueif not an.nextPermutation() : return falsevar E = newSeqWith(n,newSeq[int]())for i in 0..<n:for j in 0..<n:if isSmall(B[i],B[j]) : E[j] &= ivar dp = newSeq[int](n)let TS = E.topologicalSort(true).reversed()for e in TS :for dst in E[e]:dp[dst] .max= dp[e] + 1echo dp.max() + 1