-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy path1527B2.cpp
More file actions
executable file
·42 lines (35 loc) · 802 Bytes
/
Copy path1527B2.cpp
File metadata and controls
executable file
·42 lines (35 loc) · 802 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Problem Code: 1527B2
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
bool is_palindrome(int n, string& s) {
return equal(s.begin(), s.begin() + n / 2, s.rbegin());
}
string easy_game(int n, string& s) {
int zeros = count(s.begin(), s.end(), '0');
if (zeros & 1)
return --zeros ? "ALICE" : "BOB";
return zeros ? "BOB" : "DRAW";
}
string hard_game(int n, string& s) {
int zeros = count(s.begin(), s.end(), '0');
return ((n & 1) && s[n / 2] == '0' && zeros == 2) ? "DRAW" : "ALICE";
}
string palindrome_game(int n, string& s) {
if (is_palindrome(n, s))
return easy_game(n, s);
else
return hard_game(n, s);
}
int main() {
int t;
cin >> t;
while (t--) {
int n;
string s;
cin >> n >> s;
cout << palindrome_game(n, s) << endl;
}
return 0;
}