QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#793133 | #4234. Tic Tac Toe Counting | lukamosiashvili# | TL | 69ms | 3624kb | C++17 | 2.5kb | 2024-11-29 17:05:03 | 2024-11-29 17:05:04 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
char CH[9][9], board[9][9];
int X_won, O_won, reach;
void rec(int turn){
bool flag = 0;
for(int i = 1; i <= 3; i++){
for(int j = 1; j <= 3; j++){
if(board[i][j] != CH[i][j]) flag = 1;
}
}
if(!flag) reach = 1;
for(int i = 1; i <= 3; i++){
if(board[i][1] == 'X' && board[i][2] == 'X' && board[i][3] == 'X'){
X_won++;
return;
}
if(board[i][1] == 'O' && board[i][2] == 'O' && board[i][3] == 'O'){
O_won++;
return;
}
}
for(int j = 1; j <= 3; j++){
if(board[1][j] == 'X' && board[2][j] == 'X' && board[3][j] == 'X'){
X_won++;
return;
}
if(board[1][j] == 'O' && board[2][j] == 'O' && board[3][j] == 'O'){
O_won++;
return;
}
}
if(board[1][1] == 'X' && board[2][2] == 'X' && board[3][3] == 'X'){
X_won++;
return;
}
if(board[1][1] == 'O' && board[2][2] == 'O' && board[3][3] == 'O'){
O_won++;
return;
}
//
if(board[3][1] == 'X' && board[2][2] == 'X' && board[1][3] == 'X'){
X_won++;
return;
}
if(board[3][1] == 'O' && board[2][2] == 'O' && board[1][3] == 'O'){
O_won++;
return;
}
for(int i = 1; i <= 3; i++){
for(int j = 1; j <= 3; j++){
if(board[i][j] != '.') continue;
if(turn) board[i][j] = 'X'; else board[i][j] = 'O';
rec((turn ^ 1));
board[i][j] = '.';
}
}
}
int main(){
ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
int tes;
cin >> tes;
while(tes--){
string s;
cin >> s;
int cnt = -1;
int x = 0, o = 0;
for(int i = 1; i <= 3; i++){
for(int j = 1; j <= 3; j++){
cnt++;
CH[i][j] = s[cnt];
if(s[cnt] == 'X') x++;
if(s[cnt] == 'O') o++;
board[i][j] = '.';
}
}
X_won = 0, O_won = 0;
reach = 0;
rec(1);
if(!reach){
cout << "-1 -1\n";
continue;
}
X_won = 0, O_won = 0;
for(int i = 1; i <= 3; i++){
for(int j = 1; j <= 3; j++) board[i][j] = CH[i][j];
}
rec((x == o));
cout << X_won << " " << O_won << "\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 69ms
memory: 3624kb
input:
4 XX..O.... X...OX... OOOX.X.X. OOOXXX...
output:
191 194 232 200 0 1 -1 -1
result:
ok 4 lines
Test #2:
score: -100
Time Limit Exceeded
input:
100000 ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......