Submission #600608

# Submission time Handle Problem Language Result Execution time Memory
600608 2022-07-21T06:15:04 Z 장태환(#8468) JOI15_building3 (JOI15_building3) C++14
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
int dp[1000100][2];
int ma[1000100];
vector<int>x;
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >>N;
    int i;
    for(i=1;i<N;i++)
    {
        int a;
        cin >>a;
        x.push_back(a);
    }
    x.push_back(0);
    if(x[0]!=1)
        dp[1][0]=1;
    if(x[0]>2)
    {
        cout <<0;
        return 0;
    }
    int ma=x[0];
    int poss=1;
    for(i=2;i<=N;i++)
    {
        if(ma>=i)
            poss=0;
        if(x[i-1]>i)
        {
            cout <<0;
            return 0;
        }
        dp[i][0]=dp[i-1][0]+(poss?(ma-(i!=N)):0);
        dp[i][1]=1;
        if(x[i-1]>ma)
        {
            ma=x[i-1];
            dp[i][0]+=dp[i-1][1];
        }
        else
        {
            dp[i][1]+=dp[i-1][1];
        }
    }
    cout <<dp[N][0]+dp[N][1];
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -