結果
| 問題 |
No.497 入れ子の箱
|
| コンテスト | |
| ユーザー |
ei1333333
|
| 提出日時 | 2017-03-24 22:44:38 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 41 ms / 5,000 ms |
| コード長 | 2,258 bytes |
| コンパイル時間 | 1,009 ms |
| コンパイル使用メモリ | 88,956 KB |
| 実行使用メモリ | 44,160 KB |
| 最終ジャッジ日時 | 2024-07-05 22:10:01 |
| 合計ジャッジ時間 | 3,203 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 |
ソースコード
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
using namespace std;
#define INF (1 << 30)
typedef pair< int, int > P;
int C = ~(1 << 31), M = (1 << 16) - 1;
int n, x, y, z;
template< typename T >
T next(T a)
{
return ++a;
}
template< typename T >
T before(T a)
{
return --a;
}
vector< P > points[1080000];
set< P > dp[324000];
int main()
{
cin >> n;
vector< int > nums;
vector< vector< int > > vv;
for(int i = 0; i < n; i++) {
vector< int > v(3);
cin >> v[0] >> v[1] >> v[2];
nums.push_back(v[0]);
nums.push_back(v[1]);
nums.push_back(v[2]);
sort(begin(v), end(v));
vv.push_back(v);
}
sort(begin(nums), end(nums));
nums.erase(unique(begin(nums), end(nums)), end(nums));
for(int i = 0; i < n; i++) {
auto &v = vv[i];
v[0] = lower_bound(begin(nums), end(nums), v[0]) - begin(nums);
v[1] = lower_bound(begin(nums), end(nums), v[1]) - begin(nums);
v[2] = lower_bound(begin(nums), end(nums), v[2]) - begin(nums);
points[v[0]].push_back(P(-v[1], v[2]));
}
for(int i = 0; i < 324000; i++) {
while(!dp[i].empty())dp[i].erase(dp[i].begin());
}
dp[0].insert(P(-INF, -INF));
int res = 0;
for(int i = 0; i < 1080000; i++) {
sort(points[i].begin(), points[i].end());
for(int j = 0; j < points[i].size(); j++) {
y = -points[i][j].first;
z = points[i][j].second;
int bottom = 0, top = 324000;
while(top - bottom > 1) {
int mid = (top + bottom) / 2;
if(dp[mid].empty()) {
top = mid;
continue;
}
set< P >::iterator it = dp[mid].lower_bound(P(y, -INF));
if(it == dp[mid].begin()) {
top = mid;
continue;
}
it--;
if(it->second < z)bottom = mid;
else top = mid;
}
bottom++;
res = max(res, bottom);
dp[bottom].insert(P(y, z));
set< P >::iterator it = dp[bottom].find(P(y, z));
if(it != dp[bottom].begin() && before(it)->second <= z) {
dp[bottom].erase(it);
continue;
}
it++;
while(it != dp[bottom].end() && it->second >= z) {
dp[bottom].erase(it++);
}
}
points[i].clear();
}
cout << res << endl;
return 0;
}
ei1333333