QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#51217#4234. Tic Tac Toe CountingAmalgadon#WA 379ms4056kbC++171.1kb2022-10-01 14:30:312022-10-01 14:30:32

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-01 14:30:32]
  • Judged
  • Verdict: WA
  • Time: 379ms
  • Memory: 4056kb
  • [2022-10-01 14:30:31]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
map<string,pair<int,int>> mp;
string s;
char check(string s)
{
    if(s[0]==s[1]&&s[1]==s[2]) return s[0];
    if(s[3]==s[4]&&s[4]==s[5]) return s[3];
    if(s[6]==s[7]&&s[7]==s[8]) return s[6];
    if(s[0]==s[3]&&s[3]==s[6]) return s[0];
    if(s[1]==s[4]&&s[4]==s[7]) return s[1];
    if(s[2]==s[5]&&s[5]==s[8]) return s[2];
    if(s[0]==s[4]&&s[4]==s[8]) return s[0];
    if(s[2]==s[4]&&s[4]==s[6]) return s[2];
    return '.';
}
pair<int,int> dfs(string s, int now)
{
    if(mp.count(s)) return mp[s];
    char c=check(s);
    if(c=='X') return mp[s]=make_pair(1,0);
    if(c=='O') return mp[s]=make_pair(0,1);
    pair<int,int> res(0,0);
    for(int i=0;i<9;++i) if(s[i]=='.')
    {
        if(now) s[i]='X'; else s[i]='O';
        pair<int,int> tmp=dfs(s,now^1);
        res.first+=tmp.first, res.second+=tmp.second;
        s[i]='.';
    }
    return mp[s]=res;
}
int main()
{
    dfs(".........",1);
    int T; cin>>T;
    while(T--)
    {
        cin>>s;
        if(!mp.count(s)) cout<<"-1 -1\n";
        else cout<<mp[s].first<<" "<<mp[s].second<<"\n";
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 9ms
memory: 3980kb

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
Wrong Answer
time: 379ms
memory: 4056kb

input:

100000
.........
.........
.........
.........
.........
.........
.........
.........
.........
.........
.........
.........
.........
.........
.........
.........
.........
.........
.........
.........
.........
.........
.........
.........
.........
.........
.........
.........
.........
......

output:

131832 78192
131832 78192
131832 78192
131832 78192
131832 78192
131832 78192
131832 78192
131832 78192
131832 78192
131832 78192
131832 78192
131832 78192
131832 78192
131832 78192
131832 78192
131832 78192
131832 78192
131832 78192
131832 78192
131832 78192
131832 78192
131832 78192
131832 78192
1...

result:

wrong answer 1st lines differ - expected: '131184 77904', found: '131832 78192'