/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 768.0 KiB
#2 Accepted 12ms 576.0 KiB
#3 Accepted 12ms 572.0 KiB
#4 Accepted 9ms 564.0 KiB
#5 Accepted 9ms 540.0 KiB
#6 Accepted 9ms 556.0 KiB
#7 Accepted 5ms 540.0 KiB
#8 Accepted 3ms 772.0 KiB
#9 Accepted 2ms 540.0 KiB
#10 Accepted 2ms 772.0 KiB
#11 Accepted 3ms 560.0 KiB
#12 Accepted 3ms 328.0 KiB
#13 Accepted 3ms 332.0 KiB
#14 Accepted 4ms 596.0 KiB
#15 Accepted 3ms 796.0 KiB
#16 Accepted 3ms 540.0 KiB
#17 Accepted 3ms 560.0 KiB
#18 Accepted 3ms 332.0 KiB
#19 Accepted 9ms 564.0 KiB
#20 Accepted 16ms 580.0 KiB

Code

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

#define ll long long
#define int long long
#define all(x) (x).begin(), (x).end()
#define f(i, n) for (int i = 0; i < n; i++)
#define trace(x) cerr << #x << ": " << x << '\n'

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        int c0 = 0, c1 = 0, cm1 = 0, ans = 0;
        f(i, n)
        {
            int x;
            cin >> x;
            if (x == 0)
                c0++;
            else if (x == 1)
                c1++;
            else
                cm1++;
        }

        ll t1 = min((ll)(cm1 / 2), (ll)c1);
        ans += t1;
        cm1 -= 2 * t1;
        c1 -= t1;

        ll t2 = c1 / 3;
        ans += t2;
        c1 -= 3 * t2;

        ll t3 = min((ll)(cm1 / 2), (ll)c0);
        cm1 -= 2 * t3;
        c0 -= t3;

        ll t4 = min((ll)(c1 / 2), (ll)c0);
        c1 -= 2 * t4;
        c0 -= t4;

        ll t5 = min({(ll)cm1, (ll)c1, (ll)c0});
        cm1 -= t5;
        c1 -= t5;
        c0 -= t5;

        ll t6 = min((ll)cm1, (ll)(c0 / 2));
        cm1 -= t6;
        c0 -= 2 * t6;

        ll t7 = min((ll)c1, (ll)(c0 / 2));
        c1 -= t7;
        c0 -= 2 * t7;

        ll t8 = c0 / 3;
        c0 -= 3 * t8;

        ll t9 = cm1 / 3;
        ans -= t9;
        cm1 -= 3 * t9;

        ll t10 = min((ll)cm1, (ll)(c1 / 2));
        ans -= t10;
        cm1 -= t10;
        c1 -= 2 * t10;

        cout << ans << '\n';
    }
}

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 14:51:09
Judged At
2025-01-02 14:51:09
Judged By
Score
100
Total Time
16ms
Peak Memory
796.0 KiB