/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 38ms 324.0 KiB
#3 Accepted 39ms 556.0 KiB
#4 Accepted 20ms 324.0 KiB
#5 Accepted 20ms 320.0 KiB
#6 Accepted 18ms 532.0 KiB
#7 Accepted 11ms 532.0 KiB
#8 Accepted 5ms 532.0 KiB
#9 Accepted 5ms 532.0 KiB
#10 Accepted 4ms 532.0 KiB
#11 Accepted 5ms 348.0 KiB
#12 Accepted 8ms 532.0 KiB
#13 Accepted 9ms 324.0 KiB
#14 Accepted 9ms 540.0 KiB
#15 Accepted 9ms 532.0 KiB
#16 Accepted 10ms 532.0 KiB
#17 Accepted 5ms 532.0 KiB
#18 Accepted 4ms 768.0 KiB
#19 Accepted 21ms 324.0 KiB
#20 Accepted 51ms 568.0 KiB

Code

/*
 *   Copyright (c) 2025 Emon Thakur
 *   All rights reserved.
 */
#include<bits/stdc++.h>
using namespace std;
void solve()
{
    int n; cin >> n;
    int x,zero=0,one=0,minus=0;
    for(int i=0;i<n;i++)
    {
        cin >> x;
        zero += (x==0);
        one += (x==1);
        minus += (x<0);
    }
    x = min(one , minus/2);
    int ans = x;
    one -= x;
    minus -= x*2;
    x = one/3;
    ans += x;
    one -= x*3;
    if(zero*2 >= minus) cout<<ans<<endl;
    else
    {
        minus -= zero*2;
        ans -= minus/3;
        if(one==2) --ans;
        cout<<ans<<endl;
    }
}
int main()
{
    int t; cin>> t; while(t--) solve();
}

Information

Submit By
Type
Submission
Problem
P1152 Special Array
Language
C++17 (G++ 13.2.0)
Submit At
2025-01-05 13:24:45
Judged At
2025-01-05 13:24:45
Judged By
Score
100
Total Time
51ms
Peak Memory
768.0 KiB