Language: C++

#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<(n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) (s.substr(f-1,t-f+1))
#define ALL(a) (a).begin(),(a).end()

using namespace std;
struct Grid{ll x,y,t;};
struct Edge{ll to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=201010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(ll from,ll to,ll cost){E[from].pb({to,cost});}
};
vi A(222222);
vi rui(222222);
vvi E(222222);
vector<pair<pair<ll,ll>,pair<pair<ll,ll>,ll> > > cho;//→通り抜ける、左ととおりぬける、とまる、合計
map<pair<int,int>,int>ze;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll L;cin>>L;
  for(int i=0;i<L;i++){
    cin>>A[i];
  }
  if(L==1){
    cout<<0<<endl;
    return 0;
  }
  for(int i=0;i<L;i++){
    vi num;
    ll sum=0;
    ll gu=0;
    ll ki=0;
    while(i<L&&A[i]!=0){
      num.pb(A[i]);
      sum+=A[i];
      if(A[i]%2)ki++;
      else gu++;
      // cout<<sum<<" "<<A[i]<<endl;
      i++;
    }
    if(num.size()==0)continue;
    ll zero=0;
    while(i<L&&A[i]==0){zero++;i++;}
    ze[mp(cho.size(),cho.size()+1)]=zero;
    ze[mp(cho.size()+1,cho.size())]=zero;
    if(ki&&!gu){
      rui[cho.size()+1]+=rui[cho.size()]+sum;
      cho.pb(mp(mp(0,0),mp(mp(0,0),sum)));
    }else if(gu&&!ki){
      rui[cho.size()+1]+=rui[cho.size()]+sum;
      ll ho=num.size();
      cho.pb(mp(mp(ho,ho),mp(mp(0,0),sum)));
    }else{
      ll le=0,ri=num.size()-1;
      ll lesum=0,risum=0;
      rui[cho.size()+1]+=rui[cho.size()]+sum;
      for(int j=0;j<num.size();j++){if(num[j]%2==0){le=j;break;}}
      for(int j=num.size()-1;j>=0;j--){if(num[j]%2==0){ri=j;break;}}
      ll ha=ri-le+1;
      if(ri==num.size()-1&&le==0){
	cho.pb(mp(mp(min(gu,ki-le),min(gu,ki-(num.size()-1-ri))),mp(mp(min(ki,gu),min(ki,gu)),sum)));
      }else if(ri==num.size()-1){
      	cho.pb(mp(mp(min(gu,ki-le),min(gu,ki-(num.size()-1-ri))),mp(mp(min(ki-le,gu),min(ki,gu)),sum)));
      }else if(le==0){
      	cho.pb(mp(mp(min(gu,ki-le),min(gu,ki-(num.size()-1-ri))),mp(mp(min(ki,gu),min(ki-(num.size()-1-ri),gu)),sum)));
      }else{
 	cho.pb(mp(mp(min(gu,ki-le),min(gu,ki-(num.size()-1-ri))),mp(mp(min(ki-le,gu),min(ki-(num.size()-1-ri),gu)),sum)));
      }
    }
  }
  ll ans=llINF;
  ll sum=0;
  for(int i=0;i<cho.size();i++){
    //ここでとまるとき
    ll summ=sum+rui[cho.size()]-rui[i+1]+cho[i].S.F.F;
    //  cout<<summ<<" "<<rui[cho.size()]<<" "<<rui[i]<<" "<<sum<<" "<<cho[i].S.F.F<<endl;
    ans=min(ans,summ);
    if(i!=cho.size()-1)
      sum+=cho[i].F.F+ze[mp(i,i+1)];
  }
  sum=0;
  for(int i=cho.size()-1;i>=0;i--){
    //ここでとまるとき
    ll summ=sum+rui[i]+cho[i].S.F.S;
    //cout<<summ<<" "<<rui[i]<<" "<<sum<<" "<<cho[i].S.F.S<<endl;
    ans=min(ans,summ);
    if(i!=0)
      sum+=cho[i].F.S+ze[mp(i,i-1)];
  }
  cout<<ans<<endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:75:39: error: no matching function for call to 'min(long long int&, long long unsigned int)'
   75 |         cho.pb(mp(mp(min(gu,ki-le),min(gu,ki-(num.size()-1-ri))),mp(mp(min(ki,gu),min(ki,gu)),sum)));
      |                                    ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:75:39: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long long unsigned int')
   75 |         cho.pb(mp(mp(min(gu,ki-le),min(gu,ki-(num.size()-1-ri))),mp(mp(min(ki,gu),min(ki,gu)),sum)));
      |                                    ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:75:39: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   75 |         cho.pb(mp(mp(min(gu,ki-le),min(gu,ki-(num.size()-1-ri))),mp(mp(min(ki,gu),min(ki,gu)),sum)));
      |                                    ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:77:39: error: no matching function for call to 'min(long long int&, long long unsigned int)'
   77 |         cho.pb(mp(mp(min(gu,ki-le),min(gu,ki-(num.size()-1-ri))),mp(mp(min(ki-le,gu),min(ki,gu)),sum)));
      |                                    ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:77:39: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long long unsigned int')
   77 |         cho.pb(mp(mp(min(gu,ki-le),min(gu,ki-(num.size()-1-ri))),mp(mp(min(ki-le,gu),min(ki,gu)),sum)));
      |                                    ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:77:39: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   77 |         cho.pb(mp(mp(min(gu,ki-le),min(gu,ki-(num.size()-1-ri))),mp(mp(min(ki-le,gu),min(ki,gu)),sum)));
      |                                    ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:79:39: error: no matching function for call to 'min(long long int&, long long unsigned int)'
   79 |         cho.pb(mp(mp(min(gu,ki-le),min(gu,ki-(num.size()-1-ri))),mp(mp(min(ki,gu),min(ki-(num.size()-1-ri),gu)),sum)));
      |                                    ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:79:39: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long long unsigned int')
   79 |         cho.pb(mp(mp(min(gu,ki-le),min(gu,ki-(num.size()-1-ri))),mp(mp(min(ki,gu),min(ki-(num.size()-1-ri),gu)),sum)));
      |                                    ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:79:39: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   79 |         cho.pb(mp(mp(min(gu,ki-le),min(gu,ki-(num.size()-1-ri))),mp(mp(min(ki,gu),min(ki-(num.size()-1-ri),gu)),sum)));
      |                                    ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:79:86: error: no matching function for call to 'min(long long unsigned int, long long int&)'
   79 |         cho.pb(mp(mp(min(gu,ki-le),min(gu,ki-(num.size()-1-ri))),mp(mp(min(ki,gu),min(ki-(num.size()-1-ri),gu)),sum)));
      |                                                                                   ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:79:86: note:   deduced conflicting types for parameter 'const _Tp' ('long long unsigned int' and 'long long int')
   79 |         cho.pb(mp(mp(min(gu,ki-le),min(gu,ki-(num.size()-1-ri))),mp(mp(min(ki,gu),min(ki-(num.size()-1-ri),gu)),sum)));
      |                                                                                   ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:79:86: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long unsigned int'
   79 |         cho.pb(mp(mp(min(gu,ki-le),min(gu,ki-(num.size()-1-ri))),mp(mp(min(ki,gu),min(ki-(num.size()-1-ri),gu)),sum)));
      |                                                                                   ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:81:39: error: no matching function for call to 'min(long long int&, long long unsigned int)'
   81 |         cho.pb(mp(mp(min(gu,ki-le),min(gu,ki-(num.size()-1-ri))),mp(mp(min(ki-le,gu),min(ki-(num.size()-1-ri),gu)),sum)));
      |                                    ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:81:39: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long long unsigned int')
   81 |         cho.pb(mp(mp(min(gu,ki-le),min(gu,ki-(num.size()-1-ri))),mp(mp(min(ki-le,gu),min(ki-(num.size()-1-ri),gu)),sum)));
      |                                    ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 p