Wrong Answer
Code
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define all(x) (x).begin(), (x).end()
#define f(i, n) for (int i = 0; i < n; i++)
#define trace(x) cerr << #x << ": " << x << '\n'
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
int c0 = 0, c1 = 0, cm1 = 0, ans = 0;
f(i, n)
{
int x;
cin >> x;
if (x == 0)
c0++;
else if (x == 1)
c1++;
else
cm1++;
}
if (c1 + cm1 < 3)
{
cout << "0\n";
continue;
}
while (cm1 >= 2 and c1)
{
cm1 -= 2;
c1--;
ans++;
}
while (cm1 >= 2 and c0)
{
cm1 -= 2;
c0--;
}
while (cm1 and c0 >= 2)
{
cm1--;
c0 -= 2;
}
while (cm1 and c1 >= 2)
{
cm1--;
c1 -= 2;
ans--;
}
// cout<<ans<<' '<<c0<<' '<<c1<<' '<<cm1<<'\n';
while (c1 > 2)
{
c1 -= 3;
ans++;
}
cout << ans << '\n';
}
}
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:47:06
- Judged At
- 2025-01-02 14:47:06
- Judged By
- Score
- 1
- Total Time
- 12ms
- Peak Memory
- 580.0 KiB