Submission #826243

# Submission time Handle Problem Language Result Execution time Memory
826243 2023-08-15T11:29:25 Z AlphaMale06 Rabbit Carrot (LMIO19_triusis) C++14
0 / 100
1 ms 256 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define mp make_pair
#define F first
#define S second

pair<int, int> dp[200005][4];
const int inf = 1000000000;
signed main()
{
    int n, m;
    cin >> n >> m;
    n++;
    int a[n];
    a[0]=0;
    for(int i=1; i< n; i++)cin >> a[i];

    dp[1][0]=dp[1][1]=dp[1][2]=dp[1][3]=mp(0, 0);

    for(int i=2; i<=n; i++){
        int p=a[i-1];
        if(dp[i-1][3].S+m<p){
            dp[i][0]=dp[i][1]=mp(inf, 0);
        }
        else{
            if(dp[i-1][2].S+m<p || dp[i-1][2].F>=inf){
                dp[i][1]=mp(dp[i-1][3].F, p);
            }
            else{
                dp[i][1]=mp(dp[i-1][2].F, p);
            }
        }
        if(a[i-2]+m<p || dp[i-1][1].F>=inf){
            dp[i][0]=mp(inf, 0);
        }
        else{
            if(dp[i-1][0].F>=inf){
                dp[i][0]=mp(dp[i-1][1].F, p);
            }
            else dp[i][0]=mp(min(dp[i-1][1].F, dp[i-1][0].F), p);
        }


        if(dp[i-1][1].F>=inf && dp[i-1][0].F>=inf){
            dp[i][2]=mp(inf, 0);
        }
        else{
            if(dp[i-1][0].F>=inf){
                dp[i][2]=mp(dp[i-1][1].F+1, a[i-2]+m);
            }
            else dp[i][2]=mp(dp[i-1][0].F+1, a[i-2]+m);
        }

        if(a[i-1]==dp[i-1][3].S+m)dp[i][3]=mp(dp[i-1][3].F, a[i-1]);
        else dp[i][3]=mp(dp[i-1][3].F+1, dp[i-1][3].S+m);
    }
    for(int i=0; i<=n; i++){
       // cout << dp[i][0].F << " " << dp[i][0].S << " " << dp[i][1].F << " " << dp[i][1].S << " " << dp[i][2].F << " " << dp[i][2].S << " " << dp[i][3].F << " " << dp[i][3].S << '\n';
    }
    int mn=min({dp[n][3].F, dp[n][2].F, dp[n][1].F, dp[n][0].F});
    cout << mn << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -