/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 30ms 532.0 KiB
#3 Accepted 30ms 532.0 KiB
#4 Accepted 11ms 564.0 KiB
#5 Accepted 11ms 568.0 KiB
#6 Accepted 10ms 532.0 KiB
#7 Accepted 6ms 532.0 KiB
#8 Accepted 4ms 532.0 KiB
#9 Accepted 4ms 580.0 KiB
#10 Accepted 9ms 676.0 KiB
#11 Accepted 8ms 532.0 KiB
#12 Accepted 9ms 532.0 KiB
#13 Accepted 9ms 532.0 KiB
#14 Accepted 9ms 692.0 KiB
#15 Accepted 8ms 532.0 KiB
#16 Accepted 9ms 532.0 KiB
#17 Accepted 9ms 532.0 KiB
#18 Accepted 9ms 532.0 KiB
#19 Accepted 32ms 536.0 KiB
#20 Accepted 38ms 584.0 KiB

Code

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

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

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    while (t--){
        int n, x, ans = 0;
        cin >> n;
        vector<int> a, b, c;
        for (int i = 0; i < n; i++){
            cin >> x;
            if (x > 0) a.push_back(x);
            if (x < 0) b.push_back(x);
            if (x == 0) c.push_back(x);
        }
        while (b.size() > 1 && a.size() > 0){
            ans++;
            b.pop_back();
            b.pop_back();
            a.pop_back();
        }
        while (a.size() > 2){
            a.pop_back();
            a.pop_back();
            a.pop_back();
            ans++;
        }
        int z  = 0;
        int p = a.size(), q = b.size(), r = c.size();
        for (int i = 1; i <= r; i++){
            if (i * 2 <= p + q){
                z = i;
            } else {
                break;
            }
        }
        p = p + q;
        p -= (2 * z), r -= z;
        
        z = 0;
        if (r > 0){
            for (int i = 1; i <= p; i++){
                if (i * 2 <= r){
                    z = i;
                } else {
                    break;
                }
            }
            p -= z, r -= (2 * z);
        }
        if (p > 0) ans -= p / 3;
        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:19:41
Judged At
2025-01-02 15:19:41
Judged By
Score
100
Total Time
38ms
Peak Memory
692.0 KiB