# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1276811 | Bui_Quoc_Cuong | Money (IZhO17_money) | C++20 | 744 ms | 327680 KiB |
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<=(int)b;i++)
#define FORD(i,a,b) for(int i=a;i>=(int)b;i--)
#define ll long long
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin(),a.end()
#define BIT(mask,i) ((mask>>(i))&1)
#define MASK(a) (1LL<=((a)))
#define uni(v) sort(all(v)); v.resize(unique(all(v)) - v.begin())
#define pii pair <int, int>
#define vi vector <int>
#define vl vector <ll>
template <class A,class B>
bool maximize(A &a, const B b)
{
if(a < b){ a = b; return 1;} return 0;
}
template <class A,class B>
bool minimize(A &a, const B b)
{
if(a > b){ a = b; return 1;} return 0;
}
const int maxn = 1e6 + 5;
int n;
int a[maxn];
namespace sub3
{
vector <int> sorted[maxn];
int dp[maxn];
void solve()
{
for(int i = 1; i <= n; i++)
{
sorted[i] = sorted[i - 1];
sorted[i].push_back(a[i]);
sort(all(sorted[i]));
}
memset(dp, 0x3f, sizeof dp);
dp[0] = 0;
for(int i = 1; i <= n; i++)
{
for(int j = i; j >= 1; j--)
{
if(j != i && a[j] > a[j + 1]) break;
if(sorted[j - 1].empty() || sorted[j - 1][0] >= a[i] || sorted[j - 1].back() <= a[j] || sorted[j - 1][upper_bound(all(sorted[j - 1]), a[j]) - sorted[j - 1].begin()] >= a[i])
{
minimize(dp[i], dp[j - 1] + 1);
}
}
}
cout << dp[n];
}
}
void solve()
{
cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i];
return sub3::solve();
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#define kieuoanh "kieuoanh"
if(fopen(kieuoanh".inp","r"))
{
freopen(kieuoanh".inp","r",stdin);
freopen(kieuoanh".out","w",stdout);
}
int tst = 1;
// cin >> tst;
while(tst--) solve();
return 0;
}
컴파일 시 표준 에러 (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... |