답안 #971218

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
971218 2024-04-28T07:37:42 Z Abito Line Town (CCO23_day1problem3) C++17
0 / 25
1 ms 4444 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
#define int long long
#define ll long long
#define y1 YONE
#define free freeee
#define lcm llcm
typedef unsigned long long ull;
using namespace std;
const int N=5e5+5,M=1e6+3;
int a[N],n,dp[N][3];
bool vis[N][3];
int rec(int i,int j){
    //cout<<i<<' '<<j<<endl;
    if (i==n+1) return 0;
    if (vis[i][j+1]) return dp[i][j+1];
    dp[i][j+1]=INT_MAX;
    vis[i][j+1]=1;
    if (a[i]>=j) dp[i][j+1]=min(dp[i][j+1],rec(i+1,a[i]));
    if (a[i]<j){
        if (a[i+1]==a[i]) dp[i][j+1]=min(dp[i][j+1],rec(i+2,1)+1);
        else return dp[i][j+1]=INT_MAX;
    }
    if (a[i]==j && a[i]==-1) dp[i][j+1]=min(dp[i][j+1],rec(i+1,1)+1);
    return dp[i][j+1];
}
int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    cin>>n;
    for (int i=1;i<=n;i++) cin>>a[i];
    int x=rec(2,a[1]);
    if (x>=INT_MAX) x=-1;
    cout<<x<<endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Incorrect 1 ms 4444 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Incorrect 1 ms 4444 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Incorrect 1 ms 4444 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Incorrect 1 ms 4444 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Incorrect 1 ms 4444 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Incorrect 1 ms 4444 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Incorrect 1 ms 4444 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Incorrect 1 ms 4444 KB Output isn't correct
3 Halted 0 ms 0 KB -