/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 324.0 KiB
#2 Accepted 2ms 408.0 KiB
#3 Accepted 2ms 324.0 KiB
#4 Accepted 1ms 532.0 KiB
#5 Accepted 1ms 488.0 KiB
#6 Accepted 1ms 536.0 KiB
#7 Accepted 1ms 532.0 KiB
#8 Accepted 1ms 532.0 KiB
#9 Accepted 10ms 788.0 KiB
#10 Accepted 10ms 948.0 KiB
#11 Accepted 10ms 840.0 KiB
#12 Accepted 1ms 320.0 KiB
#13 Accepted 1ms 344.0 KiB
#14 Accepted 8ms 836.0 KiB
#15 Accepted 8ms 832.0 KiB
#16 Accepted 8ms 948.0 KiB

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