QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#72794#4234. Tic Tac Toe CountingLinshey#WA 29ms4224kbC++232.0kb2023-01-19 13:30:062023-01-19 13:30:06

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-01-19 13:30:06]
  • Judged
  • Verdict: WA
  • Time: 29ms
  • Memory: 4224kb
  • [2023-01-19 13:30:06]
  • Submitted

answer


#include <bits/stdc++.h>

using namespace std;

int f[1 << 18], g[1 << 18];

int mp[3][3], cov, bad;

inline void cons(int S)
{
    cov = 0;
    for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) if (mp[i][j] = (S >> (i * 3 + j << 1) & 3)) cov ^= 1;
    bad = 0;
    int s0 = 0, s1 = 0;
    for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) s0 += (mp[i][j] == 1), s1 += (mp[i][j] == 2);
    bad = !(s1 == s0 || s1 == s0 - 1);
}

inline int Cons()
{
    int S = 0;
    for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) S |= mp[i][j] << (i * 3 + j << 1);
    return S;
}

inline bool ck(int x)
{
    for (int i = 0; i < 3; i++)
    {
        bool is = 1;
        for (int j = 0; j < 3; j++) if (mp[i][j] != x) { is = 0; break; }
        if (is) return true;
    }
    for (int i = 0; i < 3; i++)
    {
        bool is = 1;
        for (int j = 0; j < 3; j++) if (mp[j][i] != x) { is = 0; break; }
        if (is) return true;
    }
    return (mp[0][0] == x && mp[1][1] == x && mp[2][2] == x) || (mp[2][0] == x && mp[1][1] == x && mp[0][2] == x);
}

int main()
{
    for (int S = (1 << 18) - 1; S >= 0; S--)
    {
        bool is = 0;
        for (int i = 0; i < 9; i++) if ((S >> (i << 1) & 3) == 3) { is = 1; break; }
        if (is) continue;
        cons(S);
        if (bad) continue;
        bool f1 = ck(1), f2 = ck(2);
        if (f1 && f2) continue;
        if (f1) { f[S] = 1; continue; }
        if (f2) { g[S] = 1; continue; }
        int t = cov + 1;
        for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) if (!mp[i][j])
        {
            mp[i][j] = t;
            int T = Cons();
            f[S] += f[T], g[S] += g[T];
            mp[i][j] = 0;
        }
    }
    int Q; scanf("%d", &Q); while (Q--)
    {
        char s[11];
        scanf("%s", s);
        int S = 0;
        for (int i = 0; i < 9; i++) S |= (int(s[i] != '.') + int(s[i] == 'O')) << (i << 1);
        if (f[S] == 0 && g[S] == 0) puts("-1 -1");
        else printf("%d %d\n", f[S], g[S]);
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 4ms
memory: 4132kb

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: 29ms
memory: 4224kb

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: 20ms
memory: 4132kb

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 -1
220 248
2048 756
268 144
-1 -1
-1 -1
1832 1132
-1 -1
1798 1276
220 248
-1 -1
-1 -1
-1 -1
-1 -1
14232 10176
-1 -1
1798 1276
-1 -1
-1 -1
264 188
1868 1080
239 126
-1 -1
-1 -1
-1 -1
312...

result:

wrong answer 882nd lines differ - expected: '-1 -1', found: '1 0'