/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Accepted 13ms 568.0 KiB
#3 Accepted 25ms 560.0 KiB
#4 Accepted 8ms 572.0 KiB
#5 Accepted 9ms 536.0 KiB
#6 Accepted 8ms 532.0 KiB
#7 Accepted 5ms 560.0 KiB
#8 Accepted 3ms 532.0 KiB
#9 Accepted 3ms 488.0 KiB
#10 Accepted 3ms 532.0 KiB
#11 Accepted 5ms 320.0 KiB
#12 Accepted 6ms 532.0 KiB
#13 Accepted 6ms 344.0 KiB
#14 Accepted 6ms 536.0 KiB
#15 Accepted 6ms 532.0 KiB
#16 Accepted 6ms 344.0 KiB
#17 Accepted 6ms 532.0 KiB
#18 Accepted 7ms 536.0 KiB
#19 Accepted 24ms 568.0 KiB
#20 Accepted 41ms 568.0 KiB

Code

#include <bits/stdc++.h>

using i64 = long long;

void solve() {
    int n;
    std::cin >> n;
    std::map<int, int> cnt;
    for (int i = 0; i < n; i++) {
        int x;
        std::cin >> x;
        cnt[x]++;
    }
    int s = 0;
    int t = std::min(cnt[1], cnt[-1] / 2);
    s += t;
    cnt[1] -= t;
    cnt[-1] -= t * 2;
    t = cnt[1] / 3;
    s += t;
    cnt[1] -= t * 3;
    t = std::min(cnt[0], (cnt[1] + cnt[-1]) / 2);
    int c = cnt[0] + cnt[1] + cnt[-1];
    c -= 3 * t;
    if (cnt[0] == t) {
        s -= c / 3;
    }
    std::cout << s << "\n";
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);

    int t;
    std::cin >> t;
    while (t--) {
        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:45
Judged At
2025-01-02 14:45:45
Judged By
Score
100
Total Time
41ms
Peak Memory
572.0 KiB