Submission #654157

#TimeUsernameProblemLanguageResultExecution timeMemory
654157ShahradFinancial Report (JOI21_financial)C++17
17 / 100
160 ms6836 KiB
#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 (dp[i].F < dp[j].F + bool (a[i] > dp[j].S))
                    dp[i] = mk (dp[j].F + bool (a[i] > dp[j].S), max (a[i], dp[j].S));
        cout << dp[n - 1].F << endl;
    }
}

Compilation message (stderr)

Main.cpp: In function 'int32_t main()':
Main.cpp:49:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |             if (it == vct.sz)
      |                    ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...