#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1e6 + 10;
char s[N];
void solve()
{
int n;
cin >> n;
cin >> s + 1;
if (n == 1)
{
if (s[1] == '0')
cout << "BOB" << endl;
else
cout << "DRAW" << endl;
return;
}
int sum = 0;
for (int i = 1; i <= n; i++)
if (s[i] == '0')
sum++;
if (sum == 0)
cout << "DRAW" << endl;
else if (sum % 2 == 0)
cout << "BOB" << endl;
else
{
if (sum != 1)
cout << "ALICE" << endl;
else
cout << "BOB" << endl;
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;
cin >> T;
while (T--)
{
solve();
}
return 0;
}
Codeforces Round #713 (Div. 3)D题
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define int long long
const int N = 2e5 + 10;
int S[N];
int a[N];
void solve()
{
int n;
cin >> n;
for (int i = 1; i <= n + 2; i++)
cin >> a[i], S[i] = S[i - 1] + a[i];
sort(a + 1, a + n + 3);
int sum = S[n + 2] - a[n + 1] - a[n + 2];
if (sum == a[n + 1] || sum == a[n + 2])
{
for (int i = 1; i <= n; i++)
cout << a[i] << ' ';
cout << endl;
return;
}
else
{
bool flag = false;
int id;
sum = S[n + 2] - a[n + 2];
for (int i = 1; i <= n; i++)
{
if (sum - a[i] == a[n + 2])
{
id = i;
flag = true;
}
}
if (flag)
{
for (int i = 1; i <= n + 1; i++)
{
if (id != i)
cout << a[i] << ' ';
}
cout << endl;
return;
}
}
cout << -1 << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;
cin >> T;
while (T--)
{
solve();
}
return 0;
}