/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 3ms 532.0 KiB
#2 Accepted 26ms 576.0 KiB
#3 Accepted 14ms 588.0 KiB
#4 Accepted 12ms 532.0 KiB
#5 Accepted 13ms 588.0 KiB
#6 Accepted 12ms 532.0 KiB
#7 Accepted 6ms 792.0 KiB
#8 Accepted 3ms 532.0 KiB
#9 Accepted 3ms 700.0 KiB
#10 Accepted 3ms 580.0 KiB
#11 Accepted 2ms 532.0 KiB
#12 Accepted 3ms 532.0 KiB
#13 Accepted 4ms 532.0 KiB
#14 Accepted 5ms 532.0 KiB
#15 Accepted 5ms 532.0 KiB
#16 Accepted 5ms 544.0 KiB
#17 Accepted 5ms 532.0 KiB
#18 Accepted 5ms 532.0 KiB
#19 Accepted 15ms 532.0 KiB
#20 Accepted 26ms 568.0 KiB

Code

// Author: Gourav Preet Gupta
// Language: C++

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define mp make_pair
#define float long double
#define yes  cout << "YES" << endl;
#define no  cout << "NO" << endl;
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define PI 3.141592653589793
#define Mod 1000000007

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<long long,long long> > vpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef priority_queue<ll> pq;
typedef priority_queue<pair<ll,ll> > pqp;

template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }

/*
****************************************LOVE YOU MAA***************************************************
**********************************FAMILY ABOVE ALL*****************************************************
**************************************GIVE ME SOME SUNSHINE , GIVE ME SOME RAIN************************
******************************GIVE ME ANOTHER CHANCE , I WANNA GROW UP ONCE AGAIN**********************
**************************************YE DIL MAANGE MORE***********************************************
**************************SHAURYAM DAKSHAM YUDDHE,BALIDAAN PARAM DHARMA********************************
*/

// Never Stop Trying.
// Trying to be Better than Myself.
 
// while(true)
// {
//     if(AC)
//     {
//         break;
//     }
//     else if(Contest Over)
//     {
//         Try.
//         Check out Editorial.
//         Understand.
//         Find out your Mistake.
//         Learn the topic (if new).
//         Solve Problems on that topic (if new).
//         Upsolve that problem.
//         break;
//     }
//     else
//     {
//         Try.
//         Use Pen-Paper.
//         Find errors, edge cases, etc.
//         continue;
//     }
// }

//Remember,mazaa journey mein jyaada hai,manzil main utna nahi....

const int N=1e5+5;

void solve()
{
    ll n;
    cin>>n;
    vll v(n);
    for(ll i=0; i<n; i++)
    {
        cin>>v[i];
    }
    ll zero=0ll, one=0ll, none=0ll;
    for(ll i=0; i<n; i++)
    {
        if(v[i]==0ll)
        zero++;
        else if(v[i]==1ll)
        one++;
        else 
        none++;
    }
    ll ans = 0ll;
    if(one && none)
    {
        ll mini = min(none/2,one);
        ans+=mini;
        none-=2*mini;
        one-=mini;
    }
    if(one)
    {
        ll mini = one/3;
        ans+=mini;
        one-=3*mini;
    }
    if(none && zero)
    {
        ll mini = min(none/2,zero);
        none-=2*mini;
        zero-=mini;
    }
    if(none)
    {
        ll mini = none/3;
        ans-=mini;
        none-=3*mini;
    }
    if(one && none && !zero)
    {
        ll mini = min(one/2,none);
        ans-=mini;
        one-=2*mini;
        none-=mini;
    }

    cout<<ans<<endl;

}

int main()
{    
    IOS;
    
    ll t;
    cin>>t;
    while(t--)
    {
        solve();
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1152 Special Array
Language
C++17 (G++ 13.2.0)
Submit At
2025-01-04 10:23:39
Judged At
2025-01-04 10:23:39
Judged By
Score
100
Total Time
26ms
Peak Memory
792.0 KiB