/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 340.0 KiB
#2 Accepted 2ms 320.0 KiB
#3 Accepted 3ms 320.0 KiB
#4 Accepted 2ms 320.0 KiB
#5 Accepted 1ms 532.0 KiB
#6 Accepted 1ms 516.0 KiB
#7 Accepted 2ms 320.0 KiB
#8 Accepted 2ms 324.0 KiB
#9 Accepted 1ms 324.0 KiB
#10 Accepted 1ms 324.0 KiB
#11 Accepted 2ms 344.0 KiB
#12 Accepted 2ms 484.0 KiB

Code

#ifndef COMMON_H
#define COMMON_H 1
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#include <random>
using namespace std;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define szx(x) (int)(x).size()
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
constexpr int LOG2(int x)
{
    return 32 - __builtin_clz(x) - 1;
}
#endif // COMMON_H
#ifndef DEBUG_H
#define DEBUG_H 1
#ifndef CLown1331
#define debug(...) 0
#define ASSERT(...) 0
#define dbg(...) 0
#endif
#endif // DEBUG_H
#ifndef solution_h
#define solution_h 1
namespace solution
{
const int sz = 2e5 + 105;
const int mod = 1e9 + 7;
const ll INF = 1e16;
vector <int> valid;
string board[3];
int m(int x) {
    return 1 << x;
}
int game(int mask) {
    int ret = 0;
    for (const int& validMask: valid) {
        if ((mask & validMask) == validMask) {
            return 1;
        }
    }
    for (int i = 0; i < 9; i++) {
        if (mask & m(i)) continue;
        ret |= !game(mask | m(i));
    }
    return ret;
}
void solve()
{
    valid.push_back(m(0) | m(1) | m(2));
    valid.push_back(m(3) | m(4) | m(5));
    valid.push_back(m(6) | m(7) | m(8));
    valid.push_back(m(0) | m(3) | m(6));
    valid.push_back(m(1) | m(4) | m(7));
    valid.push_back(m(2) | m(5) | m(8));
    valid.push_back(m(0) | m(4) | m(8));
    valid.push_back(m(6) | m(4) | m(2));
    int n;
    int cs = 0;
    cin >> n;
    while (n--) {
        int mask = 0;
            for (int i = 0; i < 3; i++) {
                cin >> board[i];
                for (const char &c: board[i]) {
                    mask <<= 1;
                    mask |= (c == 'X');
                }
            }
            cout << "Game #" << ++cs << ": " << (!game(mask) ? "Bob" : "Alice") << "\n";
    }
}
} // namespace solution
#endif // solution_h
#define _CRT_SECURE_NO_WARNINGS
int main()
{
    solution::solve();
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1089 Game of Tic Tac Toe
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-20 20:35:08
Judged At
2024-10-20 23:38:17
Judged By
Score
100
Total Time
3ms
Peak Memory
532.0 KiB