/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 12ms 532.0 KiB
#3 Accepted 12ms 532.0 KiB
#4 Accepted 9ms 532.0 KiB
#5 Accepted 9ms 532.0 KiB
#6 Accepted 10ms 532.0 KiB
#7 Accepted 7ms 532.0 KiB
#8 Accepted 3ms 536.0 KiB
#9 Accepted 3ms 536.0 KiB
#10 Accepted 4ms 532.0 KiB
#11 Accepted 5ms 532.0 KiB
#12 Accepted 6ms 576.0 KiB
#13 Accepted 6ms 580.0 KiB
#14 Accepted 8ms 576.0 KiB
#15 Accepted 7ms 532.0 KiB
#16 Accepted 8ms 584.0 KiB
#17 Accepted 8ms 576.0 KiB
#18 Accepted 7ms 532.0 KiB
#19 Accepted 24ms 580.0 KiB
#20 Accepted 19ms 536.0 KiB

Code

//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2")
#include <bits/stdc++.h>
//#define int long long 
#define ll long long
#define ull unsigned long long
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define max_ele(v) *max_element(v.begin(), v.end())
#define min_ele(v) *min_element(v.begin(), v.end())
#define SORT(v) sort(v.begin(), v.end())
#define REVERSE(v) reverse(v.begin(), v.end())
#define REV_SORT(v) sort((v).begin(), (v).end(), greater<>())
#define all(v) v.begin(), v.end()
#define vint vector<int>
#define u_set unordered_set
#define u_map unordered_map
#define setbit(x) __builtin_popcount(x)
#define lead_zero(x) __builtin_clz(x) 
#define trail_zero(x) __builtin_ctz(x) 
#define coutall(v) for(auto &&it : v) cout << it <<" "
#define coutnl(v) for(auto &&it : v) cout << it <<'\n'
#define cinall(v) for(auto &&it : v) cin >> it
#define cin2d(v) for(auto &&row : v) for(auto &&element : row) cin >> element;
#define cout2d(v) for (const auto& row : v) { for (const auto& element : row) cout << element << ' '; cout << '\n';}
#define nl cout << '\n';
using namespace std;
int cerrr = 1;
#define err cerr << "Thats GFG! " << cerrr++ << '\n'
const ll Inf = 0x3fffffffffffffff;
const int mod = 0x3b9aca07;

void debug_mode(){
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
}

void solve();
signed main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    //debug_mode();
    int TestCase = 1;
    cin >> TestCase; 
    int case_no = 1;
    while (TestCase--){
        // cout << "Case " << case_no++ << ": ";
        solve();
        // cout << '\n';
    }
    return 0;
}

void solve(){
    int n; cin >> n;
    int nn = 0, p = 0, z = 0;
    vint a(n);
    int cnt = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        nn += (a[i] == -1);
        p += (a[i] == 1);
        z += (a[i] == 0);
    }
    while(1){ //-1, -1, 1  inc
        if(nn <= 1 or p < 1) break;
        cnt++;
        nn -= 2;
        p--;
    }
    while(1){ // 1, 1, 1   inc
        if(p <= 2) break;
        cnt++;
        p -= 3;
    }
    while(1){//-1, -1, 0 no loss
        if(nn <= 1 or z < 1) break;
        nn -= 2;
        z--;
    }
    while(1){//0, -1, 1 no loss
        if(z < 1 or nn < 1 or p < 1) break;
        nn--;
        p--;
        z--;
    }
    while(1){ //0, 1, 1 no loss
        if(z < 1 or p <= 1) break;
        z--;
        p -= 2;
    }
    while(1){
        if(z <= 2) break;
        z -= 3;
    }
    cout << cnt - ((nn + p) / 3) << '\n';
}

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:53:39
Judged At
2025-01-02 15:53:39
Judged By
Score
100
Total Time
24ms
Peak Memory
584.0 KiB