/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 11ms 576.0 KiB
#3 Accepted 11ms 576.0 KiB
#4 Accepted 9ms 324.0 KiB
#5 Accepted 9ms 532.0 KiB
#6 Accepted 8ms 532.0 KiB
#7 Accepted 6ms 348.0 KiB
#8 Accepted 3ms 532.0 KiB
#9 Accepted 2ms 536.0 KiB
#10 Accepted 3ms 572.0 KiB
#11 Accepted 2ms 532.0 KiB
#12 Accepted 3ms 324.0 KiB
#13 Accepted 3ms 532.0 KiB
#14 Accepted 3ms 532.0 KiB
#15 Accepted 2ms 664.0 KiB
#16 Accepted 3ms 532.0 KiB
#17 Accepted 3ms 764.0 KiB
#18 Accepted 3ms 364.0 KiB
#19 Accepted 8ms 532.0 KiB
#20 Accepted 15ms 572.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define nl "\n"
#define ws " "
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define MOD 1000000007

typedef vector<ll> vi;
typedef vector<pair<ll, ll>> vii;

int main () {
    FASTIO
    int t;
    cin>>t;
    while (t--) {
        int m;
        cin>>m;
        ll p = 0, n = 0, z = 0;
        for (int i = 0; i < m; i++) {
            int x;
            cin>>x;
            if (x > 0) {
                p++;
            } else if (x < 0) {
                n++;
            } else {
                z++;
            }
        }
        ll pp = p, nn = n, zz = z;

        ll sc1 = p / 3;
        p -= (sc1 * 3);
        ll x = min (n / 2, p);
        sc1 += x;
        n -= x * 2;
        p -= x;
        ll y = min (n / 2, z);
        n -= y * 2;
        z -= y;
        ll h = min ({n, p, z});
        n -= h;
        p -= h;
        z -= h;
        ll e = min (n, z / 2);
        n -= e;
        z -= e * 2;
        ll f = n / 3;
        n -= f * 3;
        sc1 -= f;
        sc1 -= n;
        //cout<<"sc1 = "<<sc1<<nl;


        ll sc2 = min (nn / 2, pp);
        nn -= sc2 * 2;
        pp -= sc2;
        x = pp / 3;
        sc2 += x;
        pp -= x * 3;

        y = min (nn / 2, zz);
        nn -= y * 2;
        zz -= y;
        h = min ({nn, pp, zz});
        nn -= h;
        pp -= h;
        zz -= h;
        e = min (nn, zz / 2);
        nn -= e;
        zz -= e * 2;
        f = nn / 3;
        nn -= f * 3;
        sc2 -= f;
        sc2 -= nn;
        //cout<<"sc2 = "<<sc2<<nl;
        cout<<max (sc1, sc2)<<nl;

    }
    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:40:29
Judged At
2025-01-02 15:40:29
Judged By
Score
100
Total Time
15ms
Peak Memory
764.0 KiB