/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Wrong Answer 11ms 580.0 KiB
#3 Wrong Answer 13ms 532.0 KiB

Code



// In the name of ALLAH

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

typedef unsigned long long int llu;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef double dl;
typedef vector<vl> matrix;

///*******************************************************************************/

#define Code ios_base::sync_with_stdio(0);
#define By cin.tie(0);
#define Nayeem cout.tie(0);
#define endl '\n'
#define PB push_back
#define PPB pop_back
#define F first
#define S second
#define all(k) (k).begin(), (k).end()
#define MOD 1000000007
#define mems(arr,value) memset(arr, value, sizeof(arr))
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed, ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

ll gcd ( ll a, ll b ) {return __gcd ( a, b );}
ll lcm ( ll a, ll b ) {return a * ( b / gcd(a, b));}

///*******************************************************************************/

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    for(auto it = v.begin(); it != v.end(); ++it) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    for(auto it = v.begin(); it != v.end(); ++it) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename T >
ostream &operator << ( ostream & os, const multiset< T > &v ) {
    os << "[";
    for(auto it = v.begin(); it != v.end(); ++it) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    for(auto it = v.begin(); it != v.end(); ++it) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

template < typename T >
ostream &operator << ( ostream & os, const stack< T > &v ) {
    stack<T> temp = v;
    os << "{";
    bool first = true;
    while(!temp.empty()) {
        if (!first) os << ", ";
        os << temp.top();
        temp.pop();
        first = false;
    }
    return os << "}";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

void faltu () {
    cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
    for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
    cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
    cerr << arg << ' ';
    faltu(rest...);
}

///*******************************************************************************/

const double PI = 3.14159265358973; //acos(-1);
const int MAX = 1e6 + 123;
const double esp = 1e-9;
const int INF = INT_MAX;
const ll INFLL = LLONG_MAX;

///*******************************************************************************/


void find_solution() {
    
    int n; cin >> n;
    ll one = 0, neg = 0, zero = 0;

    for( int i = 0; i < n; i++ ){
        int x; cin >> x;
        if( x == 0 ) zero++;
        else if( x == 1 ) one++;
        else neg++;
    }

    int possible_ans = one / 3;

    if( zero == 0 ){
        cout << possible_ans - ( ( one % 3 ) + neg / 3 ) << endl;
    }else if( neg == 0 ){
        if( one >= zero ) {
            int c = ( one % 3 ) + zero;
            if( c >=  possible_ans ) cout << 0 << endl;
            else cout << ( possible_ans - c ) << endl;
        }else{
            cout << 0 << endl;
        }
    }else{
        if( neg >= zero ) {
            int ans = neg / 3;
            int c = ( neg % 3 ) + zero;
            if( c >=  ans ) cout << 0 << endl;
            else cout << -( ans - c ) << endl;
        }else{
            cout << 0 << endl;
        }
    }
   
}

void solve_TestCase() {
    ll hide_case; cin >> hide_case;
    for( int i = 1; i <= hide_case; i++ ){
        find_solution();
    }
}

int main() {
    Code By Nayeem
    
    //find_solution();
    solve_TestCase();
    /****** Alhamdulillah ******/
    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:58:56
Judged At
2025-01-02 15:58:56
Judged By
Score
1
Total Time
13ms
Peak Memory
580.0 KiB