/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 2ms 572.0 KiB
#2 Wrong Answer 2ms 540.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    ll n;
    cin >> n;
    
    ll a[n];
    for (ll i = 0; i < n; i++)
        cin >> a[i];
    
    vector<ll> v;
    for (ll i = 0; i < n; i++)
    {
        if (a[i] % 2)
        {
            v.push_back(i);
        }
    }
    
    if (v.size() % 2)
    {
        cout << -1;
    }
    else
    {
        ll odd = 0, c = 0;
        for (ll 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:07:54
Judged At
2024-11-11 03:35:36
Judged By
Score
0
Total Time
2ms
Peak Memory
572.0 KiB