# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1119241 | Cadoc | Financial Report (JOI21_financial) | C++14 | 4041 ms | 1864 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;
#define ll long long
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define el cout << '\n'
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define N 300005
int n, d;
int a[N];
int par[N], sz[N];
int mark[N];
int dp[N];
int get(int u){
return par[u] = (u == par[u]? u:get(par[u]));
}
int join(int u, int v){
u = get(u), v = get(v);
if(u == v) return 0;
if(sz[u] < sz[v]) swap(u, v);
sz[u] += sz[v];
par[v] = u;
return 1;
}
void Solve(){
cin >> n >> d;
for(int i=1; i<=n; ++i) cin >> a[i];
int Ans = 1;
for(int i=1; i<=n; ++i){
int l = max(1, i - d);
for(int j=i-1; j>=l; --j){
if(a[j] >= a[i]) l = max(1, j - d);
}
dp[i] = 1;
for(int j=i-1; j>=l; --j){
if(a[j] < a[i]) dp[i] = max(dp[i], dp[j] + 1);
else if(a[j] == a[i]) dp[i] = max(dp[i], dp[j]);
}
Ans = max(Ans, dp[i]);
}
cout << Ans;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define NAME "TASK"
if(fopen(NAME".inp", "r")){
freopen(NAME".inp", "r", stdin);
freopen(NAME".out", "w", stdout);
}
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... |