/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 332.0 KiB
#2 Accepted 14ms 564.0 KiB
#3 Accepted 16ms 576.0 KiB
#4 Accepted 10ms 560.0 KiB
#5 Accepted 12ms 560.0 KiB
#6 Accepted 10ms 768.0 KiB
#7 Accepted 6ms 540.0 KiB
#8 Accepted 3ms 540.0 KiB
#9 Accepted 3ms 768.0 KiB
#10 Accepted 3ms 560.0 KiB
#11 Accepted 2ms 584.0 KiB
#12 Accepted 3ms 388.0 KiB
#13 Accepted 3ms 540.0 KiB
#14 Accepted 3ms 588.0 KiB
#15 Accepted 3ms 588.0 KiB
#16 Accepted 3ms 516.0 KiB
#17 Accepted 3ms 560.0 KiB
#18 Accepted 3ms 332.0 KiB
#19 Accepted 11ms 556.0 KiB
#20 Accepted 18ms 804.0 KiB

Code

#include <bits/stdc++.h>

using namespace std;

// #include "debug.h"

void solve() {
        int n;
        cin >> n;

        map<int, int> cnt;
        for (int i = 0; i < n; ++i) {
                int x;
                cin >> x;
                ++cnt[x];
        }

        int a1 = min(cnt[1], cnt[-1] / 2);
        cnt[1] -= a1;
        cnt[-1] -= 2 * a1;

        int a2 = cnt[1] / 3;
        cnt[1] -= 3 * a2;

        int a3 = min(cnt[-1], cnt[0]);
        cnt[-1] -= min(cnt[-1], 2 * a3);

        int a4 = cnt[-1] / 3;
        cnt[-1] -= 3 * a4;

        cout << a1 + a2 - (a4 + cnt[-1]) << '\n';
}

int32_t main() {
        ios_base::sync_with_stdio(false);
        cin.tie(0);

        int tc = 1;
        cin >> tc;

        while (tc--) {
                solve();
        }
}

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 14:45:56
Judged At
2025-01-02 14:45:56
Judged By
Score
100
Total Time
18ms
Peak Memory
804.0 KiB