이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
const int maxn = 1e6 + 3;
int n;
int a[maxn];
void read()
{
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
}
int dp[maxn];
void solve()
{
dp[n+1] = 0;
for (int i = n; i >= 1; i--)
{
set <int> s;
for (int j = 1; j < i; j++)
s.insert(a[j]);
dp[i] = dp[i+1] + 1;
auto it = s.upper_bound(a[i]);
for (int j = i+1; j <= n; j++)
{
if (a[j] < a[j-1])
break;
if (it != s.end() && a[j] > *it)
break;
dp[i] = min(dp[i], dp[j+1] + 1);
}
}
cout << dp[1] << endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
read();
solve();
}
/*
6
3 6 4 5 1 2
*/
# | 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... |