/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Wrong Answer 40ms 536.0 KiB
#3 Wrong Answer 39ms 324.0 KiB

Code

#include <bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(),x.end(); 
#define F first
#define S second
#define ll long long
#define int long long

using namespace std;

const int maxn = 2e5 + 5;

int n,a[maxn];

signed main(){

	int tt = 1;
	
	cin >> tt;
	
	for(int ii = 1; ii <= tt; ii++){
		cin >> n;
	
		int cnt[3];
		cnt[0] = cnt[1] = cnt[2] = 0;
		
		for(int i = 1; i <= n; i++){
			cin >> a[i];
			cnt[a[i] + 1]++;
		}
		
		int ans = 0;
		
		while(cnt[0] > 1 && cnt[2]){
			ans++;
			cnt[0] -= 2;
			cnt[2]--;
		}
		
		while(cnt[2] > 2){
			ans++;
			cnt[2] -= 3;
		}
		
		while(cnt[0] + cnt[1] > 2){
			if(cnt[0] > 1){
				cnt[0] -= 2;
				cnt[1]--;
			}
			else {
				cnt[1] -= 2;
				cnt[0]--;
			}
		}
		
		while(cnt[0] && cnt[2]){
			if(cnt[2] > 1){
				ans--;
				cnt[2] -= 2;
				cnt[0]--;
			}
			else break;
		}
		
		cout << ans << '\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 14:49:54
Judged At
2025-01-02 14:49:54
Judged By
Score
1
Total Time
40ms
Peak Memory
536.0 KiB