結果

問題 No.497 入れ子の箱
ユーザー te-shte-sh
提出日時 2017-12-25 11:28:53
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 61 ms / 5,000 ms
コード長 1,091 bytes
コンパイル時間 677 ms
コンパイル使用メモリ 97,332 KB
実行使用メモリ 11,824 KB
最終ジャッジ日時 2023-09-03 17:47:07
合計ジャッジ時間 3,609 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 60 ms
11,764 KB
testcase_04 AC 59 ms
9,004 KB
testcase_05 AC 60 ms
10,532 KB
testcase_06 AC 60 ms
10,056 KB
testcase_07 AC 60 ms
11,044 KB
testcase_08 AC 61 ms
9,228 KB
testcase_09 AC 60 ms
11,776 KB
testcase_10 AC 61 ms
10,848 KB
testcase_11 AC 60 ms
9,532 KB
testcase_12 AC 51 ms
6,848 KB
testcase_13 AC 50 ms
6,308 KB
testcase_14 AC 50 ms
6,620 KB
testcase_15 AC 51 ms
7,004 KB
testcase_16 AC 52 ms
6,688 KB
testcase_17 AC 51 ms
8,288 KB
testcase_18 AC 57 ms
10,248 KB
testcase_19 AC 57 ms
10,836 KB
testcase_20 AC 57 ms
10,508 KB
testcase_21 AC 56 ms
10,980 KB
testcase_22 AC 57 ms
11,824 KB
testcase_23 AC 17 ms
4,380 KB
testcase_24 AC 17 ms
4,380 KB
testcase_25 AC 1 ms
4,384 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 53 ms
9,244 KB
testcase_28 AC 53 ms
9,248 KB
testcase_29 AC 53 ms
9,476 KB
testcase_30 AC 33 ms
4,376 KB
testcase_31 AC 32 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;

alias graph = Graph!int;

void main()
{
  auto n = readln.chomp.to!int;
  auto s = new int[][](n, 3);
  foreach (i; 0..n) {
    s[i] = readln.split.to!(int[]);
    s[i].sort();
  }

  auto g = new int[][](n);
  foreach (i; 0..n)
    foreach (j; 0..n)
      if (iota(3).all!(k => s[i][k] > s[j][k])) g[i] ~= j;

  auto ts = graph.topologicalSort(g);

  auto dp = new int[](n);
  dp[] = 1;

  foreach_reverse (i; ts)
    foreach (j; g[i])
      dp[i] = max(dp[i], dp[j]+1);

  writeln(dp.maxElement);
}

template Graph(Node)
{
  import std.container;

  Node[] topologicalSort(Node[][] g)
  {
    auto n = cast(Node)(g.length), h = new size_t[](n);

    foreach (u; 0..n)
      foreach (v; g[u])
        ++h[v];

    auto st = SList!Node();
    foreach (i; 0..n)
      if (h[i] == 0) st.insertFront(i);

    Node[] ans;
    while (!st.empty()) {
      auto u = st.front; st.removeFront();
      ans ~= u;
      foreach (v; g[u]) {
        --h[v];
        if (h[v] == 0) st.insertFront(v);
      }
    }

    return ans;
  }
}
0