/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Wrong Answer 33ms 560.0 KiB
#3 Wrong Answer 33ms 544.0 KiB

Code

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int solve(int n, vector<int>& A) {
    int a = 0, b = 0, c = 0;

    // Count occurrences of -1, 0, and 1
    for (int x : A) {
        if (x == -1) a++;
        else if (x == 0) b++;
        else c++;
    }

    int score = 0;

    // Form triplets of three 1's
    score += c / 3;
    c %= 3;

    // Form triplets of two 1's and one -1
    int t2 = min(c / 2, a);
    score -= t2;
    c -= t2 * 2;
    a -= t2;

    // Form triplets of three -1's
    score -= a / 3;
    a %= 3;

    return score;
}

int main() {
    int T;
    cin >> T;
    while (T--) {
        int N;
        cin >> N;
        vector<int> A(N);
        for (int i = 0; i < N; ++i) {
            cin >> A[i];
        }
        cout << solve(N, A) << endl;
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1152 Special Array
Contest
Happy New Year 2025
Language
C++17 (G++ 13.2.0)
Submit At
2025-01-02 15:14:52
Judged At
2025-01-02 15:14:52
Judged By
Score
1
Total Time
33ms
Peak Memory
560.0 KiB