Wrong Answer
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;
}
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;
}
return 0;
}
Information
- Submit By
- Type
- Submission
- Problem
- P1042 Array partition
- Language
- C++20 (G++ 13.2.0)
- Submit At
- 2024-05-06 13:11:26
- Judged At
- 2024-11-11 03:35:34
- Judged By
- Score
- 0
- Total Time
- 1ms
- Peak Memory
- 324.0 KiB