QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#433567 | #2405. Tic-Tac State | JustJie# | AC ✓ | 3ms | 3780kb | C++20 | 2.3kb | 2024-06-08 12:44:43 | 2024-06-08 12:44:43 |
Judging History
answer
/***************************************************************************************************
* author : Jie Chen (4th Year CS)
* school : Rochester Institute of Technology
* created: 06.08.2024 00:19:39
****************************************************************************************************/
#include "bits/stdc++.h"
using namespace std;
using i64 = long long;
void work(int tc) {
string t;
cin >> t;
reverse(t.begin(), t.end());
while (t.size() < 7) {
t += "0";
}
string res;
int moves = 0;
for (int i = 0; i < 6; i++) {
int v = t[i] - '0';
for (int j = 0; j < 3; j++) {
if (v & (1 << j)) {
res += '1';
if (i <= 2) {
moves++;
}
} else {
res += '0';
}
}
}
res += '0' + (t[6] & 1);
const auto divmod = [&](int x, int mod) {
return pair(x / mod, x % mod);
};
vector board(3, string(3, '.'));
for (int i = 9; i < 18; i++) {
if (res[i - 9] == '1') {
auto [r, c] = divmod(i - 9, 3);
board[r][c] = (res[i] == '1' ? 'X' : 'O');
}
}
const auto check_win = [&](char c) -> bool {
string won = string(3, c);
for (int i = 0; i < 3; i++) {
if (board[i] == won) {
return true;
}
string t;
for (int j = 0; j < 3; j++) {
t += board[j][i];
}
if (t == won) {
return true;
}
}
string t1, t2;
for (int i = 0; i < 3; i++) {
t1 += board[i][i];
t2 += board[i][3 - i - 1];
}
return t1 == won || t2 == won;
};
if (check_win('X')) {
cout << "X wins\n";
} else if (check_win('O')) {
cout << "O wins\n";
} else if (moves == 9) {
cout << "Cat's\n";
} else {
cout << "In progress\n";
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
for (int t = 1; T--; t++) {
work(t);
}
}
/*
O wins
X wins
Cat’s
In progress
O wins
X wins
Cat's
In progress
*/
// ~ Just Jie
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3540kb
input:
4 01116777 07037 01416777 050055
output:
O wins X wins Cat's In progress
result:
ok 4 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
1 00
output:
In progress
result:
ok single line: 'In progress'
Test #3:
score: 0
Accepted
time: 3ms
memory: 3560kb
input:
5477 01000004 01000001 01000002 01000010 020021 01020025 020022 01020026 020024 01000020 01020023 01020034 020030 01020031 01020032 040041 01040045 040042 01040046 040044 01000040 01040043 01040054 040050 01040051 01040052 01020064 01040064 040060 020060 060063 01060067 060065 01020061 01040061 0600...
output:
In progress In progress In progress In progress In progress In progress In progress In progress In progress In progress In progress In progress In progress In progress In progress In progress In progress In progress In progress In progress In progress In progress In progress In progress In progress ...
result:
ok 5477 lines
Test #4:
score: 0
Accepted
time: 0ms
memory: 3780kb
input:
5477 020020 01020024 01020021 01020022 01020030 040040 01040044 01040041 01040042 01040050 060061 01060065 060062 01060066 060064 01020060 01040060 01060063 01060074 060070 01060071 01060072 0100100 01100104 01100101 01100102 01100110 0120121 01120125 0120122 01120126 0120124 01020120 01100120 01120...
output:
In progress In progress In progress In progress In progress In progress In progress In progress In progress In progress In progress In progress In progress In progress In progress In progress In progress In progress In progress In progress In progress In progress In progress In progress In progress ...
result:
ok 5477 lines