# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1056888 | cpdreamer | Financial Report (JOI21_financial) | C++14 | 281 ms | 642864 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>
#include <ext/pb_ds/assoc_container.hpp>
#include <utility>
#define V vector
#define P pair
#define S second
#define F first
#define pb push_back
#define all(v) v.begin(),v.end()
typedef long long ll;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
static int called = 0;const long long MOD = 1e9+7; // 1e9 + 7
void file(){
freopen("input.txt.txt","r",stdin);
freopen("output.txt.txt","w",stdout);
}
void file(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
void modify(int &a,int v1,int v2){
if(a==-1)
a=max(v1,v2);
else
a=min(a,max(v1,v2));
}
bool dp[8000][8000];
int minimum [8000][8000];
void solve() {
int n;
cin>>n;
int d;
cin>>d;
int A[n];
for(int i=0;i<n;i++)
cin>>A[i];
V<int>vp;
for(int i=0;i<n;i++)
vp.pb(A[i]);
sort(all(vp));
auto it=unique(all(vp));
vp.resize(distance(vp.begin(),it));
map<int,int>mp;
for(int i=0;i<vp.size();i++)
mp[vp[i]]=i;
memset(dp,false,sizeof(dp));
for(int j=0;j<n;j++) {
for (int i = 0; i + j < n; i++) {
if (j == 0)
minimum[i][i + j] = A[i];
else
minimum[i][i + j] = min(A[i], minimum[i + 1][i + j]);
}
}
for(int i=0;i<n-1;i++){
int maxd=INT_MIN;
for(int j=i+1;j<n;j++){
int num_ele=j-i-1;
if(num_ele<d)
dp[i][j]=true;
else{
maxd=max(maxd,minimum[j-d][j-1]);
if(maxd<=A[i])
dp[i][j]=true;
else
dp[i][j]=false;
}
}
}
int dp1[n];
for(int i=0;i<n;i++)dp1[i]=1;
for(int i=0;i<n;i++){
for(int j=0;j<i;j++){
if(dp[j][i] && A[i]>A[j]){
dp1[i]=max(dp1[i],dp1[j]+1);
}
}
}
int ans=1;
for(int i=0;i<n;i++)
ans=max(ans,dp1[i]);
cout<<ans<<endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//file();
solve();
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... |