이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
}
컴파일 시 표준 에러 (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 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... |