結果
問題 | No.497 入れ子の箱 |
ユーザー |
![]() |
提出日時 | 2017-04-01 18:04:19 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 4 ms / 5,000 ms |
コード長 | 1,471 bytes |
コンパイル時間 | 702 ms |
コンパイル使用メモリ | 88,860 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-07 18:55:19 |
合計ジャッジ時間 | 1,854 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:62:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 62 | scanf("%d", &n); | ~~~~~^~~~~~~~~~ main.cpp:65:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 65 | scanf("%d%d%d", ds, ds + 1, ds + 2); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
/* -*- 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; }