Accepted
Code
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
int d = 0;
for (int i = 0; i < n; i++)
{
if (a[i] % 2)
{
d++;
}
}
if (d % 2)
{
cout << -1<<endl;
}
else
{
int odd = 0, c = 0;
for (int i = 0; i < n; i++)
{
if (a[i] % 2)
{
odd++;
if (odd == 2)
{
c++;
odd = 0;
}
}
else if (odd == 0)
{
c++;
}
}
cout << c<<endl;
}
return 0;
}
Information
- Submit By
- Type
- Submission
- Problem
- P1042 Array partition
- Language
- C++20 (G++ 13.2.0)
- Submit At
- 2024-05-06 13:12:49
- Judged At
- 2024-11-11 03:35:34
- Judged By
- Score
- 100
- Total Time
- 10ms
- Peak Memory
- 948.0 KiB