# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
600455 | Plurm | Financial Report (JOI21_financial) | C++11 | 46 ms | 3648 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int a[300005];
int dp[7005][7005]; // dp[last][max]
class comp{
public:
bool operator()(int x, int y){
return a[x] < a[y];
}
};
int main(){
int n, d;
scanf("%d%d",&n,&d);
for(int i = 1; i <= n; i++){
scanf("%d", a+i);
}
if(n > 7000){
vector<int> lis;
for(int i = 1; i <= n; i++){
auto it = lower_bound(lis.begin(), lis.end(), a[i]);
if(it == lis.end()) lis.push_back(a[i]);
else *it = a[i];
}
printf("%d\n", lis.size());
return 0;
}
map<int,int,comp> mp;
for(int i = 1; i <= n; i++){
for(int j = 1; j < i; j++){
if(a[j] < a[i]) continue;
// dp[i][j] <- dp[k][j]
for(int k = i-1; k >= i-d && k > 0; k--){
dp[i][j] = max(dp[i][j], dp[k][j]);
}
}
// dp[i][i]
dp[i][i] = 1;
auto it = mp.lower_bound(i);
if(it != mp.begin()){
--it;
bool ok = true;
while(it->second < i-d){
it = mp.erase(it);
if(it == mp.begin()){
ok = false;
break;
}
--it;
}
if(ok) dp[i][i] = dp[it->second][it->first] + 1;
}
for(int j = 0; j <= i; j++){
it = mp.lower_bound(j);
while(it != mp.end() && dp[it->second][it->first] <= dp[i][j]){
it = mp.erase(it);
}
if(it == mp.begin()){
mp[j] = i;
}else{
--it;
if(dp[it->second][it->first] < dp[i][j]) mp[j] = i;
}
}
}
int ans = 0;
for(int j = 0; j <= n; j++) ans = max(ans, dp[n][j]);
printf("%d\n", ans);
return 0;
}
Compilation message (stderr)
# | 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... |