# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
654163 | Shahrad | Financial Report (JOI21_financial) | C++17 | 150 ms | 6880 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 int ll
#define endl '\n'
#define sz size ()
#define all(x) x.begin(),x.end()
#define pb push_back
#define F first
#define S second
#define pii pair<int,int>
#define mk make_pair
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
const int N = 1e6 + 5;
int a[N];
stack <int> st;
vector <int> vct;
pii dp[N];
int32_t main ()
{
int n, d;
cin >> n >> d;
for (int i = 0; i < n; i++)
cin >> a[i];
if (d == 1)
{
st.push (a[n - 1]);
int ans = 1;
for (int i = n - 2; ~i; i--)
{
while (st.sz && a[i] >= st.top ())
st.pop ();
st.push (a[i]);
ans = max (ans, (int) st.sz);
}
cout << ans << endl;
}
else if (d == n)
{
for (int i = 0; i < n; i++)
{
int it = lower_bound (all (vct), a[i]) - vct.begin ();
if (it == vct.sz)
vct.pb (a[i]);
else
vct[it] = a[i];
}
cout << vct.sz << endl;
}
else
{
dp[0] = mk (1, a[0]);
for (int i = 1; i < n; i++)
for (int j = max (0ll, i - d); j < i; j++)
{
if (a[i] > dp[j].S)
{
if (dp[i].F < dp[j].F + 1)
dp[i] = mk (dp[j].F + 1, a[i]);
}
else
{
if (dp[i].F < dp[j].F)
dp[i] = dp[j];
}
}
cout << dp[n - 1].F << endl;
}
}
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... |