結果

問題 No.497 入れ子の箱
コンテスト
ユーザー tnakao0123
提出日時 2017-04-01 18:04:19
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,471 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 619 ms
コンパイル使用メモリ 111,144 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-03-29 09:52:43
合計ジャッジ時間 1,716 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/* -*- coding: utf-8 -*-
 *
 * 497.cc: No.497 入れ子の箱 - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 1000;

/* typedef */

struct Box {
  int x, y, z;
  Box() {}
  Box(int _x, int _y, int _z): x(_x), y(_y), z(_z) {}

  bool operator<(const Box &b) const {
    return x < b.x || (x == b.x && (y < b.y || (y == b.y && z < b.z)));
  }

  bool fit(const Box &b) const {
    return x < b.x && y < b.y && z < b.z;
  }

  void print() { printf("(%d,%d,%d)\n", x, y, z); }
};

/* global variables */

Box bs[MAX_N];
int dp[MAX_N];

/* subroutines */

inline void setmax(int &a, int b) { if (a < b) a = b; }

/* main */

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int ds[3];
    scanf("%d%d%d", ds, ds + 1, ds + 2);
    sort(ds, ds + 3);
    bs[i] = Box(ds[0], ds[1], ds[2]);
  }
  sort(bs, bs + n);
  //for (int i = 0; i < n; i++) bs[i].print();

  fill(dp, dp + n, 0);

  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++)
      if (bs[i].fit(bs[j])) setmax(dp[j], dp[i] + 1);

  int maxd = 0;
  for (int i = 0; i < n; i++) setmax(maxd, dp[i]);
  printf("%d\n", maxd + 1);
  return 0;
}
0