QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#419400 | #4858. Poker Game: Decision | binminh01 | AC ✓ | 2799ms | 4104kb | C++23 | 11.3kb | 2024-05-23 21:32:16 | 2024-05-23 21:32:18 |
Judging History
answer
#pragma GCC optimize("Ofast,unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define int128 __int128_t
#define double long double
#define gcd __gcd
#define lcm(a, b) ((a)/gcd(a, b)*(b))
#define sqrt sqrtl
#define log2 log2l
#define log10 log10l
#define floor floorl
#define to_string str
#define yes cout << "YES"
#define no cout << "NO"
#define trav(i, a) for (auto &i: (a))
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) (int)a.size()
#define Max(a) *max_element(all(a))
#define Min(a) *min_element(all(a))
#define Find(a, n) (find(all(a), n) - a.begin())
#define Count(a, n) count(all(a), n)
#define Upper(a, n) (upper_bound(all(a), n) - a.begin())
#define Lower(a, n) (lower_bound(all(a), n) - a.begin())
#define next_perm(a) next_permutation(all(a))
#define prev_perm(a) prev_permutation(all(a))
#define sorted(a) is_sorted(all(a))
#define sum(a) accumulate(all(a), 0)
#define sumll(a) accumulate(all(a), 0ll)
#define Sort(a) sort(all(a))
#define Reverse(a) reverse(all(a))
#define Unique(a) Sort(a), (a).resize(unique(all(a)) - a.begin())
#define pb push_back
#define eb emplace_back
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll
#define clz __builtin_clz
#define clzll __buitlin_clzll
#define ctz __builtin_ctz
#define ctzll __builtin_ctzll
#define open(s) freopen(s, "r", stdin)
#define write(s) freopen(s, "w", stdout)
#define fileopen(s) open((string(s) + ".inp").c_str()), write((string(s) + ".out").c_str());
#define For(i, a, b) for (auto i = (a); i < (b); i++)
#define Fore(i, a, b) for (auto i = (a); i >= (b); i--)
#define FOR(i, a, b) for (auto i = (a); i <= (b); i++)
#define ret(s) return void(cout << s);
const int mod = 1e9 + 7, mod2 = 998244353;
const double PI = acos(-1), eps = 1e-9;
const ull npos = string::npos;
const int dx[] = {0, 0, -1, 1}, dy[] = {-1, 1, 0, 0};
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using cd = complex<double>;
mt19937 mt(chrono::system_clock::now().time_since_epoch().count());
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<double> vdo;
typedef vector<vdo> vvdo;
typedef vector<string> vs;
typedef vector<pii> vpair;
typedef vector<vpair> vvpair;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<cd> vcd;
typedef priority_queue<int> pq;
typedef priority_queue<int, vi, greater<int>> pqg;
typedef priority_queue<ll> pqll;
typedef priority_queue<ll, vll, greater<ll>> pqgll;
ll add(ll a, ll b, int m) {if (a >= m) a%=m;if (b >= m) b%=m;a+=b;return a >= m ? a - m: a;}
ll sub(ll a, ll b, int m) {if (a >= m) a%=m;if (b >= m) b%=m;a-=b;return a < 0 ? a + m: a;}
ll mul(ll a, ll b, int m) {if (a >= m) a%=m;if (b >= m) b%=m;return a*b % m;}
ll bin_mul(ll a, ll b, ll m) {if (a >= m) a%=m;if (b >= m) b%=m;ll x = 0;while (b) {if (b & 1) x = (x + a) % m;a = (a + a) % m;b>>=1;}return x;}
ll power(ll a, ll b, int m) {ll x = 1;if (a >= m) a%=m; while (b) {if (b & 1) x = x*a % m;a = a*a % m;b>>=1;}return x;}
ll power(ll a, ll b) {ll x = 1;while (b) {if (b & 1) x = x*a;a = a*a;b>>=1;}return x;}
ll ceil(ll a, ll b) {return (a + b - 1)/b;}
ll to_int(const string &s) {ll x = 0; for (int i = (s[0] == '-'); i < sz(s); i++) x = x*10 + s[i] - '0';return x*(s[0] == '-' ? -1: 1);}
bool is_prime(ll n) {if (n < 2) return 0;if (n < 4) return 1;if (n % 2 == 0 || n % 3 == 0) return 0;for (ll i = 5; i*i <= n; i+=6) {if(n % i == 0 || n % (i + 2) == 0) return 0;}return 1;}
bool is_square(ll n) {ll k = sqrt(n); return k*k == n;}
ll factorial(int n) {ll x = 1;for (int i = 2; i <= n; i++) x*=i;return x;}
ll factorial(int n, int m) {ll x = 1;for (ll i = 2; i <= n; i++) x = x*i % m;return x;}
bool is_power(ll n, ll k) {while (n % k == 0) n/=k;return n == 1ll;}
string str(ll n) {if (n == 0) return "0"; string s = ""; bool c = 0; if (n < 0) c = 1, n = -n; while (n) {s+=n % 10 + '0'; n/=10;} if (c) s+='-'; Reverse(s); return s;}
string repeat(const string &s, int n) {if (n < 0) return ""; string x = ""; while (n--) x+=s; return x;}
string bin(ll n) {string s = ""; while (n) {s+=(n & 1) + '0'; n>>=1;} Reverse(s); return s;}
void sieve(vector<bool> &a) {int n = a.size(); a[0] = a[1] = 0; for (int i = 4; i < n; i+=2) a[i] = 0; for (int i = 3; i*i < n; i+=2) {if (a[i]) {for (int j = i*i; j < n; j+=(i << 1)) a[j] = 0;}}}
void sieve(bool a[], int n) {a[0] = a[1] = 0; for (int i = 4; i < n; i+=2) a[i] = 0; for (int i = 3; i*i < n; i+=2) {if (a[i]) {for (int j = i*i; j < n; j+=(i << 1)) a[j] = 0;}}}
void sieve(vector<int> &a) {int n = a.size(); for (int i = 2; i < n; i+=2) a[i] = 2; for (int i = 3; i*i < n; i+=2) {if (!a[i]) {for (int j = i; j < n; j+=(i << 1)) a[j] = i;}} for (int i = 3; i < n; i+=2) {if (!a[i]) a[i] = i;}}
void sieve(int a[], int n) {for (int i = 2; i < n; i+=2) a[i] = 2; for (int i = 3; i*i < n; i+=2) {if (!a[i]) {for (int j = i; j < n; j+=(i << 1)) a[j] = i;}} for (int i = 3; i < n; i+=2) {if (!a[i]) a[i] = i;}}
vector<pii> factorize(int n) {vector<pii> a; for (int i = 2; i*i <= n; i++) {if (n % i == 0) {int k = 0; while (n % i == 0) k++, n/=i; a.emplace_back(i, k);}} if (n > 1) a.emplace_back(n, 1); return a;}
int rand(int l, int r) {return uniform_int_distribution<int>(l, r)(mt);}
int Log2(int n) {return 31 - __builtin_clz(n);}
template<class T> void compress(vector<T> &a) {vector<T> b; for (T &i: a) b.push_back(i); sort(all(b)); b.resize(unique(all(b)) - b.begin()); for (T &i: a) i = lower_bound(all(b), i) - b.begin() + 1;}
template<class A, class B> istream& operator>>(istream& in, pair<A, B> &p) {in >> p.first >> p.second; return in;}
template<class A, class B> ostream& operator<<(ostream& out, const pair<A, B> &p) {out << p.first << ' ' << p.second; return out;}
template<class T> istream& operator>>(istream& in, vector<T> &a) {for (auto &i: a) in >> i; return in;}
template<class T> ostream& operator<<(ostream& out, const vector<T> &a) {for (auto &i: a) out << i << ' '; return out;}
template<class T> istream& operator>>(istream& in, vector<vector<T>> &a) {for (auto &i: a) in >> i; return in;}
template<class T> ostream& operator<<(ostream& out, const vector<vector<T>> &a) {for (auto &i: a) out << i << '\n'; return out;}
template<class T> istream& operator>>(istream& in, deque<T> &a) {for (auto &i: a) in >> i; return in;}
template<class T> ostream& operator<<(ostream& out, const deque<T> &a) {for (auto &i: a) out << i << ' '; return out;}
// istream& operator>>(istream& in, __int128_t &a) {string s; in >> s; a = 0; for (auto &i: s) a = a*10 + (i - '0'); return in;}
// ostream& operator<<(ostream& out, __int128_t a) {string s = ""; while (a > 0) {s+=(int)(a % 10) + '0'; a/=10;} Reverse(s); out << s; return out;}
char r[128], f[729];
int q[] = {1, 3, 9, 27, 81, 243};
bool same(char a, char b, char c, char d, char e) {return a == b && a == c && a == d && a == e;}
bool stra(char a, char b, char c, char d, char e) {
return (a == '2' && b == '3' && c == '4' && d == '5' && e == 'A') ||
(r[a] + 1 == r[b] && r[b] + 1 == r[c] && r[c] + 1 == r[d] && r[d] + 1 == r[e]);
}
bool cmp(const string &s, const string &t) {
return r[s[0]] < r[t[0]];
}
bool CMP(const string &s, const string &t) {
return r[s[0]] > r[t[0]];
}
pair<int, vs> score(vs a) {
sort(all(a), cmp);
vs b = a; Reverse(b);
if (a[0][0] == 'T' && a[1][0] == 'J' && a[2][0] == 'Q' && a[3][0] == 'K' && a[4][0] == 'A'
&& same(a[0][1], a[1][1], a[2][1], a[3][1], a[4][1])) return {10, a};
if (stra(a[0][0], a[1][0], a[2][0], a[3][0], a[4][0]) && same(a[0][1], a[1][1], a[2][1], a[3][1], a[4][1]))
return {9, b};
if (a[0][0] == a[3][0]) return {8, a};
if (a[1][0] == a[4][0]) return {8, b};
if ((a[0][0] == a[2][0] && a[3][0] == a[4][0])) return {7, a};
if ((a[0][0] == a[1][0] && a[2][0] == a[4][0])) return {7, b};
if (same(a[0][1], a[1][1], a[2][1], a[3][1], a[4][1])) return {6, b};
if (stra(a[0][0], a[1][0], a[2][0], a[3][0], a[4][0])) return {5, b};
if (a[0][0] == a[2][0]) {
if (r[a[3][0]] < r[a[4][0]]) swap(a[3], a[4]);
return {4, a};
}
if (a[1][0] == a[3][0]) {
a.pb(a[0]); a.erase(a.begin());
if (r[a[3][0]] < r[a[4][0]]) swap(a[3], a[4]);
return {4, a};
}
if (a[2][0] == a[4][0]) {
a.pb(a[0]); a.pb(a[1]); a.erase(a.begin(), a.begin() + 2);
if (r[a[3][0]] < r[a[4][0]]) swap(a[3], a[4]);
return {4, a};
}
vpair p;
For(i,0,5){
For(j,i+1,5){
if (a[i][0] == a[j][0]) p.eb(i, j);
}
}
if (sz(p) == 2) {
vs c{a[p[0].first], a[p[0].second], a[p[1].first], a[p[1].second]};
For(i,0,5){
if (i != p[0].first && i != p[0].second && i != p[1].first && i != p[1].second) {
c.pb(a[i]);
break;
}
}
if (r[c[0][0]] < r[c[2][0]]) swap(c[0], c[2]), swap(c[1], c[3]);
return {3, c};
}
if (sz(p) == 1) {
vs c{a[p[0].first], a[p[0].second]};
For(i,0,5){
if (i != p[0].first && i != p[0].second) c.pb(a[i]);
}
sort(c.begin() + 2, c.end(), CMP);
return {2, c};
}
return {1, b};
}
int ck(vs a, vs b) {
auto p = score(a), q = score(b);
if (p.first != q.first) return p.first < q.first;
For(i,0,5){
if (p.second[i][0] != q.second[i][0]) {
if ((p.first == 5 || p.first == 9) && (p.second[i][0] == 'A' || q.second[i][0] == 'A'))
return r[p.second[i][0]] > r[q.second[i][0]];
return r[p.second[i][0]] < r[q.second[i][0]];
}
}
return 2;
}
vs a(2), b(2), c(6);
vi make(int n) {
vi d(6);
Fore(i,5,0){
d[i] = n/q[i];
n%=q[i];
}
return d;
}
int run(int m) {
if (f[m] != -1) return f[m];
vi d = make(m);
if (Find(d, 2) == 6) {
vs x = a, y = b;
For(i,0,6){
if (!d[i]) x.pb(c[i]);
else y.pb(c[i]);
}
return (f[m] = ck(x, y));
}
int u = 0, v = 0;
For(i,0,6){
if (!d[i]) u++;
if (d[i] == 1) v++;
}
if (u == v) {
For(i,0,6){
if (d[i] == 2) {
int w = run(m - 2*q[i]);
if (f[m] == -1) f[m] = w;
else if (f[m] == 1 && w != 1) f[m] = w;
else if (f[m] == 2 && w == 0) f[m] = w;
}
}
} else {
For(i,0,6){
if (d[i] == 2) {
int w = run(m - q[i]);
if (f[m] == -1) f[m] = w;
else if (f[m] == 0 && w != 0) f[m] = w;
else if (f[m] == 2 && w == 1) f[m] = w;
}
}
}
return f[m];
}
void solve() {
cin >> a >> b >> c;
memset(f, -1, sizeof(f));
int w = run(728);
cout << (w == 0 ? "Alice": w == 1 ? "Bob": "Draw");
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
cout << fixed << setprecision(10);
FOR(i,2,9) r[i + '0'] = i;
r['T'] = 10; r['J'] = 11; r['Q'] = 12; r['K'] = 13; r['A'] = 14;
int T = 1;
cin >> T;
while (T--) {
solve();
cout << '\n';
}
cerr << "Process returned 0 (0x0) execution time : " << 0.001*clock() << " s";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4040kb
input:
9 JC 4H TS 5D JS JH JD 4S 4C 4D JC 4H TS 5D TH TC TD 5S 5H 5C JC 4H TS 5D 4S JS 5S TH TC TD 7C 3C 7H TH 3S 3H 3D 2C 4H 5S 7C 3C 7H TH 2H 4H 5H 6H 8H 9H 7C 3C 7H TH TS 3S 2S 2H 4C 4D 2D KH 4D JC 2S 2H 2C KS KC KD 2D KH 4D JC 4S 4H 4C JS JH JD 2D KH 4D JC 2S KS 4S JS JH JD
output:
Alice Bob Draw Alice Bob Draw Alice Bob Draw
result:
ok 9 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 4100kb
input:
1 AS 2H 2S 6H 3S 3H 4S 4H 5S 5H
output:
Bob
result:
ok single line: 'Bob'
Test #3:
score: 0
Accepted
time: 1ms
memory: 4104kb
input:
1 5D 9H KC 6H 9C QH JH 3C AC 9S
output:
Alice
result:
ok single line: 'Alice'
Test #4:
score: 0
Accepted
time: 2799ms
memory: 4076kb
input:
100000 5C JS KS 7S 4D 2D KH 6S 6D 6H 2C KS 7D 5D 5S AH 3S 9C JH 5H 9D 4D 3H TS 2D 2C 7H 3D AH 3S KS 8H 7H QD TH 4H QS 8S 6D TD JS 8D 4H 2S AH 2H 2C 6S 4C 8S JS KD 4S 2D JH 4C 6S QD AH 7C 9D 4H QH JS KH QC 6S 5D JC AD KD 5D 4C TC 4H 2C TD 7S 6S QH 3C 5C QC 9D QH 5D AC 7D 8C 8S 4S 6H 9C 8C JC 7S QH 6C...
output:
Bob Bob Bob Alice Bob Alice Bob Bob Alice Alice Alice Alice Bob Alice Alice Alice Alice Alice Bob Bob Alice Bob Bob Alice Alice Alice Alice Alice Alice Alice Alice Alice Alice Alice Alice Bob Alice Alice Bob Bob Alice Alice Bob Bob Bob Alice Alice Alice Bob Bob Alice Alice Alice Alice Alice Alice Al...
result:
ok 100000 lines