| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1347111 | nambanana987 | Financial Report (JOI21_financial) | C++20 | 4094 ms | 2632 KiB |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
// Tối ưu nhập xuất
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, d;
cin >> n >> d;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<int> dp(n, 1);
int max_len = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < i; j++) {
// Điều kiện 1: Giá trị phải nhỏ hơn
if (a[j] < a[i]) {
// Điều kiện 2: Kiểm tra tính hợp lệ của khoảng cách D
// Trong thực tế, với O(n^2) vét cạn, ta kiểm tra xem
// có thể nhảy từ j đến i hay không.
bool reachable = true;
int count_larger = 0;
// Kiểm tra các phần tử ở giữa j và i
// Nếu có một đoạn liên tiếp dài >= d mà các giá trị đều >= a[i]
// thì j không thể "với" tới i được.
for (int k = i - 1; k > j; k--) {
if (a[k] >= a[i]) {
count_larger++;
} else {
count_larger = 0;
}
if (count_larger >= d) {
reachable = false;
break;
}
}
if (reachable) {
dp[i] = max(dp[i], dp[j] + 1);
}
}
}
max_len = max(max_len, dp[i]);
}
cout << max_len << endl;
return 0;
}| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
