# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1119124 | Cadoc | Financial Report (JOI21_financial) | C++14 | 4040 ms | 8468 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 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];
for(int i=1; i<=n; ++i){
par[i] = i;
sz[i] = 1;
}
for(int i=1; i<=n; ++i){
dp[i] = 1;
for(int j=max(1, i-d); j<i; ++j) if(a[j] >= a[i]) join(i, j);
for(int j=1; j<i; ++j) if(j >= i-d || get(i) == get(j)){
if(a[j] < a[i]){
dp[i] = max(dp[i], dp[j] + 1);
}
}
}
int Ans = 1;
for(int i=1; i<=n; ++i) if(get(n) == get(i)) 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... |