/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Accepted 28ms 564.0 KiB
#3 Accepted 26ms 572.0 KiB
#4 Accepted 10ms 536.0 KiB
#5 Accepted 10ms 532.0 KiB
#6 Accepted 8ms 532.0 KiB
#7 Accepted 5ms 532.0 KiB
#8 Accepted 3ms 532.0 KiB
#9 Accepted 3ms 536.0 KiB
#10 Accepted 4ms 532.0 KiB
#11 Accepted 3ms 328.0 KiB
#12 Accepted 5ms 532.0 KiB
#13 Accepted 7ms 536.0 KiB
#14 Accepted 8ms 568.0 KiB
#15 Accepted 7ms 532.0 KiB
#16 Accepted 7ms 572.0 KiB
#17 Accepted 7ms 532.0 KiB
#18 Accepted 7ms 532.0 KiB
#19 Accepted 26ms 532.0 KiB
#20 Accepted 36ms 576.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set1 = tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update>;
#define op()                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define yes cout << "YES\n";
#define no cout << "NO\n";
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a * b) / gcd(a, b))
#define PI 2.0 * acos(0.0)
#define Dpos(n) fixed << setprecision(n)

typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
const ll MOD = 1e9 + 7;
const ll N = 1e5 + 1;

void solve()
{
    ll n, a = 0, b = 0, c = 0, num;
    cin >> n;
    while (n--)
    {
        cin >> num;
        if (num == -1)
            a++;
        else if (num == 0)
            b++;
        else
            c++;
    }
    num = 0;
    while (a >= 2 && c)
    {
        num++, a -= 2, c--;
    }
    while (a && b && a + b >= 3)
    {
        if (a >= 2)
        {
            a -= 2, b--;
        }
        else
        {
            a--, b -= 2;
        }
    }
    num -= (a / 3);
    a %= 3, b %= 3;
    if (a == 1)
    {
        if (b)
        {
            b = 0, c--;
        }
        else
        {
            num--, c -= 2;
        }
    }
    if (b == 1)
        c -= 2;
    else if (b == 2)
        c -= 1;
    num += (c / 3);
    cout << num << endl;
}
int main()
{
    op() int tc = 1;
    cin >> tc;

    for (int t = 1; t <= tc; t++)
    {
        // cout << "Case " << t << ": ";
        solve();
    }
}

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:05:13
Judged At
2025-01-02 15:05:13
Judged By
Score
100
Total Time
36ms
Peak Memory
576.0 KiB