Submission #968269

# Submission time Handle Problem Language Result Execution time Memory
968269 2024-04-23T09:09:32 Z phoenix0423 Line Town (CCO23_day1problem3) C++17
0 / 25
1 ms 2396 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pll;
#define fastio ios::sync_with_stdio(false), cin.tie(0)
#pragma GCC optimize("Ofast")
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define int long long
#define lowbit(x) x&-x
const int maxn = 1e6 + 5;
const int N = 1e6 + 3;
const int INF = 1e18;
int a[maxn], dp[maxn][2];

signed main(void){
    fastio;
    int n;
    cin>>n;
    for(int i = 0; i < n; i++) cin>>a[i];
    int ans = INF;
    for(int i = 0; i < n; i++){
        if(a[i] == 1){
            if(i && a[i - 1] == 1) dp[i + 1][0] = dp[i - 1][0] + 2;
            else dp[i + 1][0] = INF;
        }
        else{
            dp[i][0] = dp[i - 1][0];
        }
    }
    for(int i = n - 1; i >= 0; i--){
        if(a[i] == -1){
            if(i < n - 1 && a[i + 1] == -1) dp[i][1] = dp[i + 2][1] + 1;
            else dp[i][1] = INF;
        }
        else{
            dp[i][1] = dp[i + 1][1];
        }
    }
    for(int i = 0; i <= n; i++) ans = min(ans, dp[i][0] + dp[i][1]);
    cout<<(ans < INF ? ans : -1)<<"\n";
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -