結果
問題 | No.497 入れ子の箱 |
ユーザー |
![]() |
提出日時 | 2017-06-30 10:07:21 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 6 ms / 5,000 ms |
コード長 | 1,118 bytes |
コンパイル時間 | 506 ms |
コンパイル使用メモリ | 47,232 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-04 20:32:18 |
合計ジャッジ時間 | 1,469 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:76:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 76 | scanf("%d%d%d", &x, &y, &z); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include<cstdio> #include<vector> #include<algorithm> using namespace std; using vi=vector<int>; using vvi=vector<vi>; using ll=long long; class box_t { int x, y, z; public: box_t(int x, int y, int z) { if(x>y) swap(x, y); if(x>z) swap(x, z); if(y>z) swap(y, z); this->x=x; this->y=y; this->z=z; } bool operator<(const box_t&rhs) const { if(x!=rhs.x) return x<rhs.x; if(y!=rhs.y) return y<rhs.y; return z<rhs.z; } bool greater(box_t& rhs) { return (x>rhs.x && y>rhs.y && z>rhs.z); } void print(void) { printf("%d %d %d\n", x, y, z); } }; int solve(vector<box_t>&b) { int n=b.size(); vector<int> dp(n, 1); for(int i=0;i<n;i++) { for(int j=0;j<i;j++) { if(b[i].greater(b[j])) { dp[i]=max(dp[i], dp[j]+1); } } } int ret=dp[0]; for(int i=1;i<n;i++) { ret=max(ret, dp[i]); } return ret; } int main(void) { int n; while(scanf("%d", &n)==1) { vector<box_t> b; for(int i=0;i<n;i++) { int x, y, z; scanf("%d%d%d", &x, &y, &z); b.push_back(box_t(x, y, z)); } sort(b.begin(), b.end()); printf("%d\n", solve(b)); } return 0; }