1 solutions
-
0
Bullet LV 4 @ 2024-03-29 11:36:38
Author code (Kamonasish Roy) :
#include<bits/stdc++.h>
using namespace std;
const long long M=2e5+10,MOD=2000000007;
typedef long long ll;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int t=1;
// cin>>t;
while(t--){
int n;
cin>>n;
int cnt=0;
int sum=0;
for(int i=1;i<=n;i++){
int a;
cin>>a;
sum+=a;
sum%=2;
cnt+=(sum==0);
}
if(sum)cnt=-1;
cout<<cnt<<"\n";
}
return 0;
}Tester Code (Jahirul Islam Hridoy) :
void solve()
{
int n , Ans = 0 , oddNum = 0; cin >> n ; int a[n] ;
for(int i = 0 ; i < n ; i++) {
cin >> a[i] ;
if(a[i] & 1) oddNum++ ;
}
if(oddNum & 1) Ans = -1 ;
else {
oddNum = 0 ;
for(auto it : a) {
if(it & 1) {
oddNum++ ;
if(oddNum == 2) oddNum = 0 , Ans++ ;
}
else {
if(!oddNum) Ans++ ;
}
}
}
cout << Ans << endl ;
}
int main()
{
Heart
int t ; t = 1 ; while(t--) solve() ;
}
- 1
Information
- ID
- 1042
- Difficulty
- 6
- Category
- Beginners Click to Show
- Tags
- (None)
- # Submissions
- 83
- Accepted
- 23
- Accepted Ratio
- 28%
- Uploaded By