/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 1ms 324.0 KiB
#3 Accepted 1ms 532.0 KiB
#4 Accepted 1ms 484.0 KiB
#5 Accepted 1ms 324.0 KiB
#6 Accepted 1ms 532.0 KiB
#7 Accepted 1ms 496.0 KiB
#8 Accepted 1ms 392.0 KiB
#9 Accepted 623ms 1.387 MiB
#10 Accepted 621ms 1.418 MiB
#11 Accepted 611ms 1.324 MiB
#12 Accepted 1ms 324.0 KiB
#13 Accepted 1ms 320.0 KiB
#14 Accepted 17ms 1.527 MiB
#15 Accepted 17ms 1.527 MiB
#16 Accepted 17ms 1.527 MiB

Code

#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> lst(n);
    for (int i = 0; i < n; i++) {
        cin >> lst[i];
    }
    vector<int> odd;
    vector<int> even;
    bool odd_len = true;

    for (int i = 0; i < n; i++) {
        if (lst[i] % 2 == 0) {
            if (odd_len == true) {
                even.push_back(lst[i]);
            }
        } else {
            odd.push_back(lst[i]);
            odd_len = false;
            int jug = 0;
            for (int j = 0; j < odd.size(); j++) {
                jug += odd[j];
            }
            if (jug % 2 == 0) {
                odd_len = true;
                even.push_back(jug);
            }
        }
    }
    int ans;
    if (odd_len == true) {
        ans = even.size();
    } else {
        ans = -1;
    }
    
    cout << ans << endl;

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1042 Array partition
Language
C++17 (G++ 13.2.0)
Submit At
2024-04-02 18:12:29
Judged At
2024-11-11 03:36:25
Judged By
Score
100
Total Time
623ms
Peak Memory
1.527 MiB