/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 14ms 544.0 KiB
#3 Accepted 14ms 560.0 KiB
#4 Accepted 10ms 548.0 KiB
#5 Accepted 10ms 548.0 KiB
#6 Accepted 9ms 588.0 KiB
#7 Accepted 6ms 540.0 KiB
#8 Accepted 3ms 540.0 KiB
#9 Accepted 3ms 492.0 KiB
#10 Accepted 3ms 332.0 KiB
#11 Accepted 3ms 540.0 KiB
#12 Accepted 3ms 540.0 KiB
#13 Accepted 4ms 540.0 KiB
#14 Accepted 3ms 768.0 KiB
#15 Accepted 3ms 588.0 KiB
#16 Accepted 4ms 516.0 KiB
#17 Accepted 3ms 540.0 KiB
#18 Accepted 3ms 520.0 KiB
#19 Accepted 11ms 540.0 KiB
#20 Accepted 17ms 332.0 KiB

Code

// I AM A MUSLIM

#include "bits/stdc++.h"

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

#define fast_io std::ios::sync_with_stdio(0);std::cin.tie(0)
#define lli long long int
#define flush fflush(stdout)
#define new_line printf("\n")
#define yn(a, b) printf("%s\n", (a) >= (b) ? "Yes":"No")
#define amodm(a, M) (((a)%M+M)%M)
// #define int lli

using pii = std::pair<int,int>;

const int MOD = 1000000007;
const int mxN = 200100;

signed main() {
    int testCases=1;
    scanf("%d",&testCases);
    
    for (int TC = 1; TC <= testCases; TC++) {
        int n;
        scanf("%d",&n);
        int cnt[3] = {0};
        for (int i = 0, v; i < n; i++) {
            scanf("%d",&v);
            if (v == -1) cnt[2]++;
            else cnt[v]++;
        }
        
        int ans = 0;
        while (cnt[2] >= 2 && cnt[1] >= 1) {
            cnt[2] -= 2;
            cnt[1]--;
            ans++;
        }
        
        if (cnt[1]) {
            if (cnt[2] == 1) {
                if (cnt[0] == 0) {
                    ans--;
                    cnt[1] -= 2;
                }
            }
            ans += cnt[1]/3;
        } else {
            while (cnt[2] >= 2 && cnt[0] >= 1) {
                cnt[2] -= 2;
                cnt[0]--;
            }
            ans -= cnt[2]/3;
        }
        
        printf("%d\n", ans);
        
    }
    
    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:16:24
Judged At
2025-01-02 15:16:24
Judged By
Score
100
Total Time
17ms
Peak Memory
768.0 KiB