/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Wrong Answer 41ms 548.0 KiB
#3 Wrong Answer 41ms 560.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
int main()
{
    ll tc;
    cin>>tc;
    while(tc--)
    {
        ll n;
        cin>>n;
        map<ll,ll>mp;
        vector<ll>v(n);
        for(int i=0;i<n;i++)
        {
            cin>>v[i]; mp[v[i]]++;
        }
        ll o=mp[1];
        ll z=mp[0];
        ll m=mp[-1];
        ll ans=0;
        while(1)
        {
            ll x=0;
            if(m>=2 && o>=1)
            {
                ans++;
                m-=2;
                o-=1;
            }
            else if(o>=3)
            {
                ans++;
                o-=3;
            }
            else if(m>=2 && z>=1)
            {
                z--;
                m-=2;
            }
            else if(m>=1 && o>=1 && z>=1)
            {
                m--;
                o--;
                z--;
            }
            else if(m>=1 && z>=2)
            {
                m--;
                z-=2;
            }
            else if(z>=3)
            {
                z-=3;
                
            }
            else if(z>=2 && o>=1)
            {
                z-=2;
                o--;
            }
            else if(z>=1 && o>=2)
            {
                z--;
                o-=2;
            }
            else if(m>=1 && o>=2)
            {
                ans--;
                m--;
                o-=2;
            }
            else
                break;
            
        }
        cout<<ans<<endl;
        
    }
}

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:07:18
Judged At
2025-01-02 15:07:18
Judged By
Score
1
Total Time
41ms
Peak Memory
560.0 KiB