#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<array<int, 4>> a(n);
for(auto& i : a) {
for(auto& j : i) {
cin >> j;
}
}
auto cmp = [](const auto& l, const auto& r) {
return min(l[1], l[3]) < min(r[1], r[3]);
};
auto ok = [&](int i, int j) {
return a[j][0] > a[i][1] && a[j][2] > a[i][3];
};
sort(a.begin(), a.end(), cmp);
// for(auto& i : a) {
// for(auto& j : i) {
// cout << j << " ";
// }
// cout << "\n";
// }
// bool can[n][n];
// memset(can, false, sizeof can);
//
// for(int i = 0; i < n; i++) {
// for(int j = i+1; j < n; j++) {
// can[i][j] = can[j][i] = ok(i, j);
// }
// }
vector<int> dp(n, 1);
vector<int> mx(n, 1);
for(int i = 0; i < n; i++) {
int l = 0, r = i-1, ans = -1;
while(l <= r) {
int mid = (l + r) / 2;
if (ok(mid, i)) {
ans = mid;
l = mid + 1;
}
else {
r = mid - 1;
}
}
if (ans == -1) continue;
dp[i] = dp[i] + mx[ans];
mx[i] = max(mx[i-1], dp[i]);
}
cout << mx[n-1] << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Unexpected end of file - int32 expected |
2 |
Incorrect |
1 ms |
204 KB |
Unexpected end of file - int32 expected |
3 |
Incorrect |
1 ms |
332 KB |
Unexpected end of file - int32 expected |
4 |
Incorrect |
1 ms |
348 KB |
Unexpected end of file - int32 expected |
5 |
Incorrect |
1 ms |
332 KB |
Unexpected end of file - int32 expected |
6 |
Incorrect |
2 ms |
432 KB |
Unexpected end of file - int32 expected |
7 |
Incorrect |
3 ms |
460 KB |
Unexpected end of file - int32 expected |
8 |
Incorrect |
5 ms |
460 KB |
Unexpected end of file - int32 expected |
9 |
Incorrect |
5 ms |
696 KB |
Unexpected end of file - int32 expected |
10 |
Incorrect |
10 ms |
1260 KB |
Unexpected end of file - int32 expected |
11 |
Incorrect |
13 ms |
1464 KB |
Unexpected end of file - int32 expected |
12 |
Incorrect |
25 ms |
2760 KB |
Unexpected end of file - int32 expected |
13 |
Incorrect |
28 ms |
3280 KB |
Unexpected end of file - int32 expected |
14 |
Incorrect |
62 ms |
3896 KB |
Unexpected end of file - int32 expected |
15 |
Incorrect |
40 ms |
4028 KB |
Unexpected end of file - int32 expected |
16 |
Incorrect |
41 ms |
4328 KB |
Unexpected end of file - int32 expected |
17 |
Incorrect |
55 ms |
4572 KB |
Unexpected end of file - int32 expected |
18 |
Incorrect |
86 ms |
4772 KB |
Unexpected end of file - int32 expected |
19 |
Incorrect |
45 ms |
5112 KB |
Unexpected end of file - int32 expected |
20 |
Incorrect |
50 ms |
5348 KB |
Unexpected end of file - int32 expected |