QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#33778 | #4234. Tic Tac Toe Counting | henrique4d# | TL | 3ms | 3620kb | C++ | 3.9kb | 2022-06-05 03:16:09 | 2022-06-05 03:16:10 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int ganhador[270] = {0};
char win(char tabuleiro[3][3], int countx, int counto, int x, int y, char caractere){
//cout << "win" << endl;
char tabuleiroAux[3][3];
for (int i=0; i<3; i++){
for (int j=0; j<3; j++){
tabuleiroAux[i][j] = tabuleiro[i][j];
}
}
if (x!=-1 and y!=-1){
tabuleiroAux[x][y] = caractere;
}
bool ganhador1 = false;
bool ganhador2 = false;
if (tabuleiroAux[0][0] == 'X' and tabuleiroAux[0][1] == 'X' and tabuleiroAux[0][2] == 'X'){ganhador1 = true;}
if (tabuleiroAux[1][0] == 'X' and tabuleiroAux[1][1] == 'X' and tabuleiroAux[1][2] == 'X'){ganhador1 = true;}
if (tabuleiroAux[2][0] == 'X' and tabuleiroAux[2][1] == 'X' and tabuleiroAux[2][2] == 'X'){ganhador1 = true;}
if (tabuleiroAux[0][0] == 'X' and tabuleiroAux[1][0] == 'X' and tabuleiroAux[2][0] == 'X'){ganhador1 = true;}
if (tabuleiroAux[0][1] == 'X' and tabuleiroAux[1][1] == 'X' and tabuleiroAux[2][1] == 'X'){ganhador1 = true;}
if (tabuleiroAux[0][2] == 'X' and tabuleiroAux[1][2] == 'X' and tabuleiroAux[2][2] == 'X'){ganhador1 = true;}
if (tabuleiroAux[0][0] == 'X' and tabuleiroAux[1][1] == 'X' and tabuleiroAux[2][2] == 'X'){ganhador1 = true;}
if (tabuleiroAux[2][0] == 'X' and tabuleiroAux[1][1] == 'X' and tabuleiroAux[0][2] == 'X'){ganhador1 = true;}
if (tabuleiroAux[0][0] == 'O' and tabuleiroAux[0][1] == 'O' and tabuleiroAux[0][2] == 'O'){ganhador2 = true;}
if (tabuleiroAux[1][0] == 'O' and tabuleiroAux[1][1] == 'O' and tabuleiroAux[1][2] == 'O'){ganhador2 = true;}
if (tabuleiroAux[2][0] == 'O' and tabuleiroAux[2][1] == 'O' and tabuleiroAux[2][2] == 'O'){ganhador2 = true;}
if (tabuleiroAux[0][0] == 'O' and tabuleiroAux[1][0] == 'O' and tabuleiroAux[2][0] == 'O'){ganhador2 = true;}
if (tabuleiroAux[0][1] == 'O' and tabuleiroAux[1][1] == 'O' and tabuleiroAux[2][1] == 'O'){ganhador2 = true;}
if (tabuleiroAux[0][2] == 'O' and tabuleiroAux[1][2] == 'O' and tabuleiroAux[2][2] == 'O'){ganhador2 = true;}
if (tabuleiroAux[0][0] == 'O' and tabuleiroAux[1][1] == 'O' and tabuleiroAux[2][2] == 'O'){ganhador2 = true;}
if (tabuleiroAux[2][0] == 'O' and tabuleiroAux[1][1] == 'O' and tabuleiroAux[0][2] == 'O'){ganhador2 = true;}
if (ganhador1 and ganhador2) return 'n';
if (ganhador1) return 'X';
if (ganhador2) return 'O';
vector<pair<int,int>> to_process;
for (int i=0; i<3; i++){
for (int j=0; j<3; j++){
if (tabuleiroAux[i][j] == '.'){
to_process.push_back(make_pair(i,j));
}
}
}
for (int i=0; i<to_process.size(); i++){
if (countx == counto){
ganhador[win(tabuleiroAux, countx+1, counto, to_process[i].first ,to_process[i].second, 'X')]++;
}
else{
ganhador[win(tabuleiroAux, countx, counto+1, to_process[i].first ,to_process[i].second, 'O')]++;
}
}
return 'a';
}
int main(){
int n;
cin >> n;
char tabuleiro[3][3];
for (int k=0; k<n; k++){
int countx = 0, counto = 0;
for (int i=0; i<3; i++){
for (int j=0; j<3; j++){
cin >> tabuleiro[i][j];
if (tabuleiro[i][j] == 'X') countx++;
else if (tabuleiro[i][j] == 'O') counto++;
}
}
if ( !(countx == counto or countx == counto + 1) ){
cout << -1 << " " << -1 << endl;
continue;
}
char aux = win(tabuleiro, countx, counto, -1, -1, 'x');
ganhador[aux]++;
if (ganhador['n']){
cout << -1 << " " << -1 << endl;
continue;
}
cout << ganhador['X'] << " " << ganhador['O'] << endl;
ganhador['X'] = 0;
ganhador['O'] = 0;
ganhador['n'] = 0;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 3620kb
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 ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......... ......
output:
131184 77904 131184 77904 131184 77904 131184 77904 131184 77904 131184 77904 131184 77904 131184 77904 131184 77904 131184 77904 131184 77904 131184 77904 131184 77904 131184 77904 131184 77904 131184 77904 131184 77904 131184 77904 131184 77904 131184 77904 131184 77904 131184 77904 131184 77904 1...