/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 1ms 540.0 KiB
#3 Accepted 1ms 364.0 KiB
#4 Accepted 1ms 548.0 KiB
#5 Accepted 1ms 540.0 KiB
#6 Accepted 1ms 492.0 KiB
#7 Accepted 1ms 452.0 KiB
#8 Accepted 1ms 540.0 KiB
#9 Accepted 9ms 932.0 KiB
#10 Accepted 9ms 936.0 KiB
#11 Accepted 9ms 940.0 KiB
#12 Accepted 1ms 540.0 KiB
#13 Accepted 1ms 344.0 KiB
#14 Accepted 7ms 728.0 KiB
#15 Accepted 7ms 772.0 KiB
#16 Accepted 7ms 724.0 KiB

Code

#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define endl '\n'
#define Endl '\n'

using namespace std;

const int N = 2e5 + 5;
int tc, n, m, a[N];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); // cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    long long sum = accumulate(a, a + n, 0ll);
    if (sum & 1) {
        cout << -1 << endl;
    } else {
        int cnt = 0;
        sum = 0;
        for (int i = 0; i < n; i++) {
            sum += a[i];
            if (sum % 2 == 0) {
                cnt++;
                sum = 0;
            }
        }
        cout << cnt << endl;
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1042 Array partition
Contest
TLE_Headquarters - round #1
Language
C++17 (G++ 13.2.0)
Submit At
2024-03-27 17:00:32
Judged At
2024-03-27 17:00:32
Judged By
Score
100
Total Time
9ms
Peak Memory
940.0 KiB