/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Wrong Answer 13ms 568.0 KiB
#3 Wrong Answer 14ms 772.0 KiB

Code

#include <bits/stdc++.h>
#define ll long long
#define endl '\n'

using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int tt; cin >> tt;
	while (tt--) {
		int n, y; cin >> n;
		map<int, int> mp;
		for (int i = -1; i < 2; i++) mp[i] = 0;
		for (int i = 0; i < n; i++) {
			cin >> y;
			mp[y]++;
		}

		int zero = mp[0], one = mp[1], minus_one = mp[-1];

		int sum1 = (one / 3) - (minus_one / 3);
		int oneLeft = one % 3;
		int minusLeft = minus_one % 3;
		if (minusLeft == 2 && oneLeft != 0) sum1++;
		else if (minusLeft == 1 && zero == 0) sum1--;

		int sum2 = 0;

		if (one >= minus_one / 2) {
			sum2 += minus_one / 2;
			minusLeft = minus_one % 2;
			one -= sum2;
		}
		else {
			sum2 += one;
			minusLeft = minus_one - one;
			one = 0;
		}

		if (one >= 3) {
			sum2 += one / 3;
			oneLeft %= 3;
		}

		if (minusLeft) {
			if (zero == 0) sum2 -= minusLeft;
		}

		cout << max(sum1, sum2) << '\n';
	}

	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 16:11:16
Judged At
2025-01-02 16:11:16
Judged By
Score
1
Total Time
14ms
Peak Memory
772.0 KiB