/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 0ms 284.0 KiB
#2 Wrong Answer 15ms 436.0 KiB

Code

#include <stdio.h>

int calculateMaxScore(int N, int* arr) {
    int count1 = 0, count_minus1 = 0, count0 = 0;

    for (int i = 0; i < N; i++) {
        if (arr[i] == 1) count1++;
        else if (arr[i] == -1) count_minus1++;
        else count0++;
    }

    int score = 0;

    // Use pairs of -1s and one 1 to get a score of 1
    while (count_minus1 >= 2 && count1 >= 1) {
        score += 1;
        count_minus1 -= 2;
        count1 -= 1;
    }

    // Use three 1s to get a score of 1
    while (count1 >= 3) {
        score += 1;
        count1 -= 3;
    }

    // Use three -1s to get a score of -1
    while (count_minus1 >= 3) {
        score -= 1;
        count_minus1 -= 3;
    }

    // Handle any remaining combinations
    while (count0 >= 1 && (count1 >= 2 || count_minus1 >= 2)) {
        score += 0;
        count0 -= 1;
        if (count1 >= 2) {
            count1 -= 2;
        } else if (count_minus1 >= 2) {
            count_minus1 -= 2;
        }
    }

    return score;
}

int main() {
    int T;
    scanf("%d", &T);

    while (T--) {
        int N;
        scanf("%d", &N);

        int arr[N];
        for (int i = 0; i < N; i++) {
            scanf("%d", &arr[i]);
        }

        printf("%d\n", calculateMaxScore(N, arr));
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1152 Special Array
Contest
Happy New Year 2025
Language
C99 (GCC 13.2.0)
Submit At
2025-01-02 15:53:35
Judged At
2025-01-02 15:53:35
Judged By
Score
0
Total Time
15ms
Peak Memory
436.0 KiB