/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 11ms 532.0 KiB
#3 Accepted 11ms 524.0 KiB
#4 Accepted 9ms 532.0 KiB
#5 Accepted 10ms 512.0 KiB
#6 Accepted 11ms 532.0 KiB
#7 Accepted 8ms 532.0 KiB
#8 Accepted 5ms 532.0 KiB
#9 Accepted 4ms 532.0 KiB
#10 Accepted 5ms 324.0 KiB
#11 Accepted 5ms 532.0 KiB
#12 Accepted 6ms 532.0 KiB
#13 Accepted 8ms 532.0 KiB
#14 Accepted 8ms 532.0 KiB
#15 Accepted 7ms 532.0 KiB
#16 Accepted 7ms 320.0 KiB
#17 Accepted 8ms 572.0 KiB
#18 Accepted 7ms 532.0 KiB
#19 Accepted 22ms 532.0 KiB
#20 Accepted 18ms 532.0 KiB

Code

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

#define endl '\n'
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

void solve(){
    int n;
    cin>>n;
    int cnt0=0,cnt1 =0, cntn1=0;
    for(int i=0; i<n; i++){
        int x;
        cin>>x;
        if(x==0) cnt0++;
        else if(x==1) cnt1++;
        else cntn1++;
    }

    int result = 0;
    if(cntn1 >= 2*cnt1){
        result += cnt1;
        cntn1 -= (2*cnt1);
        cnt1 = 0;
        
        if(cntn1 >= 2*cnt0){
            cntn1 -= (2*cnt0);
            cnt0 = 0;
        }
        else{
            cntn1 =0;
            cnt0 =0;
        }
        result -= (cntn1/3);
    }
    else{
        result += cntn1/2;
        cnt1 -= cntn1/2;
        cntn1 %= 2;

        result += cnt1/3;
        cnt1 %= 3;

        if(!cnt0 and cntn1) result--;

    }
    cout<<result<<endl;
}

signed main(){
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    optimize();

    ll t;
    cin>>t;
    for(ll i=1; i<=t; i++){
        solve();
    }
    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:33:05
Judged At
2025-01-02 15:33:05
Judged By
Score
100
Total Time
22ms
Peak Memory
572.0 KiB