TCTCTOE - Editorial

This gave a 2, which I understand to be correct? Am I missing something?
Thanks anyway! :smiley:

Yes :slight_smile: Who makes the first move?

Oh, I’m stupid, thanks a lot!

1 Like

how that position is not reachable if u don’t mind explaining pls?
1
OXX
XOX
__O

X can’t have made a greater number of moves if O wins

2 Likes

ahhhh gotcha!! thanks man… that was such a silly mistake from my side :grimacing:

1 Like

The answers you have posted to these test cases are wrong. You are generating the wrong output for test cases where both “X” and “O” have won the game, which is and unreachable position and should give 3.

The correct outputs (from my solution) are:

1
2
1
3
3
2
2
3
3
1
3
3
1
2
2
2
3
3
3
1
1
3
1
3
3

Solution: 46626402 | CodeChef (No bro plz see the code again that is not the error) this test case is working fine

1
XXX
XOO
XOO

@satyankar_2005 is correct: the answer to the testcase:

1
XXX
OXO
XOO

is 1.

Solution: 46626402 | CodeChef Bro still getting error …there is something else which we r not able to figureout

bro i enter this test case and I got my output (3) as expected see…the SS

Again: the answer should be 1.

Answers of TC posted by me is same as you, no change. I just forgot to copy the answer of last TC, i.e., 25th Test case which is also 3

Try comparing it with my code , everyone has different style of implementing. Its hard to say where your code fails. You can also brute check at which case your code is failing, as there are only 3**9 cases

How do you prove that the encoding method used will be unique for all possible states?

hi,can you find the wrong case in my code?
the answers here are right in my code

Already have, unless you’ve updated your code since :slight_smile:

The same testcase as this one:

1 Like

can anyone tell. me why i am getting WA

#include <iostream>
using namespace std;
int wins(char board[][3],char ch)
{ int res=0;
if(board[0][0]==ch&&board[0][0]==board[0][1]&&board[0][1]==board[0][2])
res++;
if(board[0][0]==ch&&board[0][0]==board[1][0]&&board[1][0]==board[2][0])
res++;
if(board[0][0]==ch&&board[0][0]==board[1][1]&&board[1][1]==board[2][2])
res++;
if(board[0][2]==ch&&board[0][2]==board[1][1]&&board[1][1]==board[2][0])
res++;
if(board[1][0]==ch&&board[1][0]==board[1][1]&&board[1][1]==board[1][2])
res++;
if(board[2][0]==ch&&board[2][0]==board[2][1]&&board[2][1]==board[2][2])
res++;
if(board[0][1]==ch&&board[0][1]==board[1][1]&&board[1][1]==board[2][1])
res++;
if(board[0][2]==ch&&board[0][2]==board[1][2]&&board[1][2]==board[2][2])
res++;
if(res!=0)
return res;
else
return 0;
}
int main()
{
int t;
cin>>t;
while(t--)
{
char mat[3][3];
int x=0,o=0;
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
cin>>mat[i][j];
if(mat[i][j]=='X')
x++;
else if(mat[i][j]=='O')
o++;
}
}
if(x==o||x==o+1)
{
    int xx=wins(mat,'X');
int oo=wins(mat,'O');

        if(xx>=2||oo>=2)
        cout<<"3"<<endl;
   
        else if(xx&&oo)
        {
            cout<<"3"<<endl;
        }
            
        else if(xx)
        {      if(x==o+1)
            cout<<"1"<<endl;
            else
            cout<<"3"<<endl;
        }
        else if(oo)
        {
            if(x==o)
            cout<<"1"<<endl;
            else
            cout<<"3"<<endl;
        }
        else
        {      if(xx+oo==9)
            cout<<"1"<<endl;
            else
            cout<<"2"<<endl;
        }

    }
    else
    {
        cout<<"3"<<endl;
    }
}
}

Please either format your code or (better!) link to your submission - the forum software has mangled it and it won’t compile! :slight_smile:

Should’nt it be 3? As count(‘X’)!=count(‘O’)+1 as first symbol starts with ‘X’

1 Like