제출 #654163

#제출 시각아이디문제언어결과실행 시간메모리
654163ShahradFinancial Report (JOI21_financial)C++17
17 / 100
150 ms6880 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 (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;
    }
}

컴파일 시 표준 에러 (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...