Submission #918744

#TimeUsernameProblemLanguageResultExecution timeMemory
918744AbitoLine Town (CCO23_day1problem3)C++17
0 / 25
0 ms344 KiB
#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; int a[N],n; 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 ans=INT_MAX; for (int i=1;i<=n+1;i++){ int x=0;bool ok=true; for (int j=1;j<i;j++){ if (a[j]==-1) continue; int r=j; for (int k=j;k<i;k++){ if (a[k]==1) r=k; else break; } if ((r-j+1)%2==0) x+=(r-j+1)/2; else ok=false; j=r; } for (int j=i;j<=n;j++){ if (a[j]==1) continue; int r=j; for (int k=j;k<=n;k++){ if (a[k]==-1) r=k; else break; } if ((r-j+1)%2==0) x+=(r-j+1)/2; else ok=false; j=r; }if (ok) ans=min(x,ans); }if (ans==INT_MAX) ans=-1; cout<<ans<<endl; return 0; }
#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...