QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#104853#4234. Tic Tac Toe CountingYanagi_Origami#WA 86ms7340kbC++203.3kb2023-05-12 07:15:472023-05-12 07:15:50

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.
  • [2023-05-12 07:15:50]
  • Judged
  • Verdict: WA
  • Time: 86ms
  • Memory: 7340kb
  • [2023-05-12 07:15:47]
  • Submitted

answer

#include <iostream>
#include <cstdio>
#include <cmath>
#include <map>
#include <algorithm>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;i++)
typedef long long ll;
char s[10],S[4][4];
map<ll,ll> ans1,ans2,vis;
ll encode(char a[4][4]){
    ll res=0;
    rep(i,1,3) rep(j,1,3){
        if(a[i][j]=='X'){
            res=res*3+1;
        }
        if(a[i][j]=='O'){
            res=res*3+2;
        }
        if(a[i][j]=='.'){
            res=res*3;
        }
    }
    return res;
}
int check(char a[4][4]){
    int ans=0;
    rep(i,1,3){
        if(a[i][1]==a[i][2]&&a[i][2]==a[i][3]){
            if(a[i][1]=='X'){
                ans|=1;
            }
            if(a[i][1]=='O'){
                ans|=2;
            }
        }
    }
    rep(i,1,3){
        if(a[1][i]==a[2][i]&&a[2][i]==a[3][i]){
            if(a[1][i]=='X'){
                ans|=1;
            }
            if(a[1][i]=='O'){
                ans|=2;
            }
        }
    }
    if(a[1][1]==a[2][2]&&a[2][2]==a[3][3]){
        if(a[2][2]=='X'){
            ans|=1;
        }
        if(a[2][2]=='O'){
            ans|=2;
        }
    }
    if(a[3][1]==a[2][2]&&a[2][2]==a[1][3]){
        if(a[2][2]=='X'){
            ans|=1;
        }
        if(a[2][2]=='O'){
            ans|=2;
        }
    }
    //if(ans!=0) puts("HERE");
    return ans;
}
pair<ll,ll> dfs(char a[4][4]){
    ll cd=encode(a);
    //printf("%lld\n",cd);
    if(vis[cd]){
        return make_pair(ans1[cd],ans2[cd]);
    }
    vis[cd]=1;
    ll res = check(a);
    if(res==3){
        ans1[cd]=-1,ans2[cd]=-1;
        return make_pair(ans1[cd],ans2[cd]);
    }
    if(res==1){
        ans1[cd]=1,ans2[cd]=0;
        return make_pair(ans1[cd],ans2[cd]);
    }
    if(res==2){
        ans1[cd]=0,ans2[cd]=1;
        return make_pair(ans1[cd],ans2[cd]);
    }
    int s1=0,s2=0;
    rep(i,1,3) rep(j,1,3){
        if(a[i][j]=='X') s1++;
        if(a[i][j]=='O') s2++;
    }
    ans1[cd]=0,ans2[cd]=0;
    if(s1==s2){
        rep(i,1,3) rep(j,1,3){
            if(a[i][j]=='.'){
                a[i][j]='X';
                auto ret = dfs(a);
                //puts("why?");
                a[i][j]='.';
                ans1[cd]+=ret.first;
                ans2[cd]+=ret.second;
            }
        }
    }else{
        if(s1==s2+1){
            rep(i,1,3) rep(j,1,3){
                if(a[i][j]=='.'){
                    a[i][j]='O';
                    auto ret = dfs(a);
                    //puts("why??");
                    a[i][j]='.';
                    ans1[cd]+=ret.first;
                    ans2[cd]+=ret.second;
                }
            }
        }else{
            ans1[cd]=-1,ans2[cd]=-1;
            return make_pair(ans1[cd],ans2[cd]);
        }
    }
    //printf("#%lld %lld %lld\n",cd,ans1[cd],ans2[cd]);
    return make_pair(ans1[cd],ans2[cd]);
}
int main(){
    char a[4][4]={0};
    rep(i,1,3) rep(j,1,3) a[i][j]='.';
    dfs(a);
    int T; scanf("%d",&T);
    while(T--){
        scanf("%s",s+1);
        rep(i,1,3) rep(j,1,3){
            a[i][j]=s[(i-1)*3+j];
        }
        auto ans = dfs(a);
        printf("%lld %lld\n",ans.first,ans.second);
    }
    return 0;
}
/*
4
XX..O....
X...OX...
OOOX.X.X.
OOOXXX...
*/

詳細信息

Test #1:

score: 100
Accepted
time: 11ms
memory: 4552kb

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: 0
Accepted
time: 28ms
memory: 4696kb

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...

result:

ok 100000 lines

Test #3:

score: -100
Wrong Answer
time: 86ms
memory: 7340kb

input:

100000
.........
X........
O........
.X.......
XX.......
OX.......
.O.......
XO.......
OO.......
..X......
X.X......
O.X......
.XX......
XXX......
OXX......
.OX......
XOX......
OOX......
..O......
X.O......
O.O......
.XO......
XXO......
OXO......
.OO......
XOO......
OOO......
...X.....
X..X.....
O.....

output:

131184 77904
14652 7896
-1 -1
14232 10176
-1 -1
1798 1276
-1 -1
2048 756
-1 -1
14652 7896
-1 -1
1832 1132
-1 -1
1 0
220 248
2048 756
268 144
-1 -1
-1 -1
1832 1132
-1 -1
1798 1276
220 248
-1 -1
-1 -1
-1 -1
0 1
14232 10176
-1 -1
1798 1276
-1 -1
-1 -1
264 188
1868 1080
239 126
-1 -1
-1 -1
-1 -1
312 152...

result:

wrong answer 14th lines differ - expected: '-1 -1', found: '1 0'