Submission #968271

#TimeUsernameProblemLanguageResultExecution timeMemory
968271phoenix0423Line Town (CCO23_day1problem3)C++17
0 / 25
1 ms2396 KiB
#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] + 1; else dp[i + 1][0] = INF; } else{ dp[i + 1][0] = dp[i][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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...