結果

問題 No.497 入れ子の箱
ユーザー simansiman
提出日時 2022-01-02 01:38:05
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 5,000 ms
コード長 1,699 bytes
コンパイル時間 1,450 ms
コンパイル使用メモリ 142,596 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-04-19 04:25:31
合計ジャッジ時間 3,030 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 8 ms
11,264 KB
testcase_04 AC 7 ms
11,264 KB
testcase_05 AC 9 ms
11,264 KB
testcase_06 AC 9 ms
11,264 KB
testcase_07 AC 8 ms
11,136 KB
testcase_08 AC 9 ms
11,264 KB
testcase_09 AC 9 ms
11,136 KB
testcase_10 AC 9 ms
11,264 KB
testcase_11 AC 8 ms
11,264 KB
testcase_12 AC 15 ms
11,264 KB
testcase_13 AC 15 ms
11,264 KB
testcase_14 AC 15 ms
11,264 KB
testcase_15 AC 14 ms
11,188 KB
testcase_16 AC 14 ms
11,264 KB
testcase_17 AC 14 ms
11,136 KB
testcase_18 AC 7 ms
11,184 KB
testcase_19 AC 8 ms
11,264 KB
testcase_20 AC 7 ms
11,240 KB
testcase_21 AC 8 ms
11,252 KB
testcase_22 AC 8 ms
11,136 KB
testcase_23 AC 7 ms
11,136 KB
testcase_24 AC 9 ms
11,264 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 13 ms
11,264 KB
testcase_28 AC 12 ms
11,264 KB
testcase_29 AC 12 ms
11,252 KB
testcase_30 AC 7 ms
11,264 KB
testcase_31 AC 7 ms
11,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

struct Box {
  int x;
  int y;
  int z;

  Box(int x = -1, int y = -1, int z = -1) {
    this->x = x;
    this->y = y;
    this->z = z;
  }

  bool operator<(const Box &n) const {
    return max(x, max(y, z)) > max(n.x, max(n.y, n.z));
  }
};

bool can_include(Box &b1, Box &b2) {
  if (b1.x > b2.x && b1.y > b2.y && b1.z > b2.z) return true;
  if (b1.x > b2.x && b1.y > b2.z && b1.z > b2.y) return true;
  if (b1.x > b2.y && b1.y > b2.x && b1.z > b2.z) return true;
  if (b1.x > b2.y && b1.y > b2.z && b1.z > b2.x) return true;
  if (b1.x > b2.z && b1.y > b2.y && b1.z > b2.x) return true;
  if (b1.x > b2.z && b1.y > b2.x && b1.z > b2.y) return true;

  return false;
}

int main() {
  int N;
  cin >> N;
  vector<Box> box_list;

  for (int i = 0; i < N; ++i) {
    Box box;
    cin >> box.x >> box.y >> box.z;
    box_list.push_back(box);
  }

  sort(box_list.begin(), box_list.end());
  ll dp[N + 1][N + 1];
  memset(dp, 0, sizeof(dp));
  ll ans = 1;

  for (int i = 1; i <= N; ++i) {
    Box &box = box_list[i - 1];
    dp[i][i] = 1;

    for (int j = 1; j < i; ++j) {
      dp[i][j] = dp[i - 1][j];
      Box &p_box = box_list[j - 1];
      if (not can_include(p_box, box)) continue;

      /*
      fprintf(stderr, "(%d, %d, %d) -> (%d, %d, %d)\n",
          p_box.x, p_box.y, p_box.z, box.x, box.y, box.z);
          */
      dp[i][i] = max(dp[i][i], dp[i][j] + 1);
      ans = max(ans, dp[i][i]);
    }
  }

  cout << ans << endl;

  return 0;
}
0