Submission #1067358

# Submission time Handle Problem Language Result Execution time Memory
1067358 2024-08-20T15:33:09 Z DucNguyen2007 Money (IZhO17_money) C++14
0 / 100
1 ms 2396 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
const int maxN=1e6+5;
const ll inf=2e18;
int n,a[maxN+1];
ll dp[maxN+1];
int main()
{
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        dp[i]=inf;
    }
    dp[0]=0;
    for(int i=1;i<=n;i++)
    {
        int prev=a[i];
        for(int j=i;j>=1;j--)
        {
            if(a[j]<=prev)
            {
                dp[i]=min(dp[i],dp[j-1]+1);
                prev=a[j];
            }
            else break;
        }
    }
    cout<<dp[n];
}
/*6
3 6 4 5 1 2*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 0 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 0 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 0 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 0 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -