/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 13ms 572.0 KiB
#3 Accepted 13ms 356.0 KiB
#4 Accepted 8ms 772.0 KiB
#5 Accepted 10ms 584.0 KiB
#6 Accepted 9ms 580.0 KiB
#7 Accepted 9ms 668.0 KiB
#8 Accepted 3ms 540.0 KiB
#9 Accepted 4ms 728.0 KiB
#10 Accepted 3ms 908.0 KiB
#11 Accepted 3ms 816.0 KiB
#12 Accepted 3ms 600.0 KiB
#13 Accepted 3ms 588.0 KiB
#14 Accepted 3ms 540.0 KiB
#15 Accepted 4ms 588.0 KiB
#16 Accepted 3ms 588.0 KiB
#17 Accepted 3ms 560.0 KiB
#18 Accepted 3ms 484.0 KiB
#19 Accepted 9ms 540.0 KiB
#20 Accepted 15ms 820.0 KiB

Code

/*
 *Copyright (c) Swadheen Islam Robi (SIR01)
 *Created on Thu Jan 02 2025 9:38:59 PM
 */
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pie 2*(acos(0.0))
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define pb push_back
#define endl "\n"
#define lcm(a,b) (a*b)/(__gcd<ll>(a,b))
#define mod 1000000007
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.rbegin(),v.rend())
#define ALLAHU_AKBAR ios::sync_with_stdio(false); cin.tie(nullptr);

void Bullet()
{
    ll n;cin>>n;
    vector<ll>v(n);
    ll o=0,one=0,mi=0;
    for(auto &a:v) {
        cin>>a;
        if(a==0)o++;
        else if(a==1)one++;
        else mi++;
    }
    ll sum = 0;

    while(mi>1){
        if(one>0){
            sum++; mi-=2; one--;
        }
        else if(o>0){
            mi-=2; o--;
        }
        else{
            sum--;
            mi-=3;
        }
        
    }

    while(one>2){
        sum++;
        one-=3;
    }
    // if(mi>1){
    //     while(mi>1 && o!=0){
    //     mi-=2;
    //     o--;
    //     }
    // }//mi = 1
    
    if(mi==1 && o>1){
        mi--; o-=2;
    }
    else if(mi==1 && o==1){
        mi--; o--; one--;
    }
    else if(mi==1 && o==0){
        sum--; mi--; one-=2;
    }
    if(o>0 && one>1){
        one-=2; o--;
        
    }
    cout<<sum<<endl;

    
}

int main() {
    ALLAHU_AKBAR

    ll t = 1;
    cin>>t;
    while(t--)
    {
        Bullet();
    }
    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 16:16:02
Judged At
2025-01-02 16:16:02
Judged By
Score
100
Total Time
15ms
Peak Memory
908.0 KiB