QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#608342#5509. Kooky Tic-Tac-Toehzy99999AC ✓68ms3672kbC++205.0kb2024-10-03 20:52:052024-10-03 20:52:05

Judging History

你现在查看的是最新测评结果

  • [2024-10-03 20:52:05]
  • 评测
  • 测评结果:AC
  • 用时:68ms
  • 内存:3672kb
  • [2024-10-03 20:52:05]
  • 提交

answer

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#define x first
#define y second
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 7;
int T;
int n, m;
string g[N];
bool st[N][N];
int dx[8] = {-1, -1, 0, 1, 1, 1, 0, -1}, dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int calc(int x, int y, int k, char str)
{
    int res = 0;
    while (x >= 1 && x <= n && y >= 1 && y <= n && g[x][y] == str)
    {
        res++;
        x += dx[k], y += dy[k];
    }
    return res;
}
bool check()
{
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
        {
            for (int k = 0; k < 4; k++)
            {
                if (g[i][j] != '.')
                {
                    int cnt = 1 + calc(i + dx[k], j + dy[k], k, g[i][j]) + calc(i + dx[k + 4], j + dy[k + 4], k + 4, g[i][j]);
                    if (cnt >= m)
                        return 1;
                }
            }
        }
    return 0;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> T;
    while (T--)
    {
        cin >> n >> m;
        for (int i = 1; i <= n; i++)
            cin >> g[i], g[i] = ' ' + g[i];
        int type = 0; // 0:NIE 1:WIN 2:DRAW
        PII res;
        if (check())
        {
            for (int i = 1; i <= n && !type; i++)
                for (int j = 1; j <= n && !type; j++)
                {
                    if (g[i][j] == '.')
                        continue;
                    char temp = g[i][j];
                    g[i][j] = '.';
                    if (!check())
                    {
                        res = {i, j};
                        type = 1;
                    }
                    g[i][j] = temp;
                }
            if (!type)
            {
                cout << "NIE" << endl;
                continue;
            }
        }
        else
        {
            type = 2;
            for (int i = 1; i <= n && type == 2; i++)
                for (int j = 1; j <= n && type == 2; j++)
                    if (g[i][j] == '.')
                        type = 0;
            if (!type)
            {
                cout << "NIE" << endl;
                continue;
            }
        }
        vector<PII> arr, brr;
        int a = 0, b = 0; // a:o b:x
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++)
                if (g[i][j] != '.')
                    if (g[i][j] == 'o')
                    {
                        a++;
                        if (res != (PII){i, j})
                            arr.push_back({i, j});
                    }
                    else
                    {
                        b++;
                        if (res != (PII){i, j})
                            brr.push_back({i, j});
                    }
        if (type == 1)
        {
            if (g[res.x][res.y] == 'o') // o WIN
            {
                if (a == b + 1 || a == b)
                    cout << "TAK" << endl;
                else
                {
                    cout << "NIE" << endl;
                    continue;
                }
                if (arr.size() < brr.size())
                    swap(arr, brr);
                int idx = 0;
                while (idx < arr.size())
                {
                    cout << arr[idx].x << ' ' << arr[idx].y << endl;
                    if (idx < brr.size())
                        cout << brr[idx].x << ' ' << brr[idx].y << endl;
                    idx++;
                }
                cout << res.x << ' ' << res.y << endl;
            }
            else // x WIN
            {
                if (a + 1 == b || a == b)
                    cout << "TAK" << endl;
                else
                {
                    cout << "NIE" << endl;
                    continue;
                }
                if (arr.size() > brr.size())
                    swap(arr, brr);
                int idx = 0;
                while (idx < brr.size())
                {
                    cout << brr[idx].x << ' ' << brr[idx].y << endl;
                    if (idx < arr.size())
                        cout << arr[idx].x << ' ' << arr[idx].y << endl;
                    idx++;
                }
                cout << res.x << ' ' << res.y << endl;
            }
        }
        else // DRAW
        {
            if (a == b || a == b + 1 || a + 1 == b)
                cout << "TAK" << endl;
            else
            {
                cout << "NIE" << endl;
                continue;
            }
            int idx = 0;
            if (arr.size() < brr.size())
                swap(arr, brr);
            while (idx < arr.size())
            {
                cout << arr[idx].x << ' ' << arr[idx].y << endl;
                if (idx < brr.size())
                    cout << brr[idx].x << ' ' << brr[idx].y << endl;
                idx++;
            }
        }
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3568kb

input:

7
3 3
x.o
xxx
o.o
4 3
xx.x
...o
..o.
.o..
3 3
xoo
oxx
xoo
3 2
xoo
oxx
xoo
3 3
xox
.o.
xox
3 2
xo.
..x
xo.
3 3
x..
.x.
..x

output:

TAK
1 1
1 3
2 2
3 1
2 3
3 3
2 1
TAK
1 1
3 3
1 2
4 2
1 4
2 4
TAK
1 2
1 1
1 3
2 2
2 1
2 3
3 2
3 1
3 3
NIE
NIE
NIE
NIE

result:

ok correct (7 test cases)

Test #2:

score: 0
Accepted
time: 10ms
memory: 3672kb

input:

10000
3 3
x.o
xxx
o.o
3 3
xoo
oxx
xoo
3 2
xoo
oxx
xoo
3 3
xox
.o.
xox
3 2
xo.
..x
xo.
3 2
oox
.xo
o.x
5 5
xxx..
xxo.x
xoo..
xxxox
.oooo
3 3
xxx
.o.
oo.
3 2
x.o
xo.
..o
3 2
..x
xxo
.o.
3 3
xxo
o..
oxo
3 2
oox
..x
...
3 3
xxo
...
.ox
3 3
.xo
...
oox
3 3
.x.
xo.
o.o
3 2
o..
xxo
.ox
3 2
x.x
xoo
x.o
3 2
...

output:

TAK
1 1
1 3
2 2
3 1
2 3
3 3
2 1
TAK
1 2
1 1
1 3
2 2
2 1
2 3
3 2
3 1
3 3
NIE
NIE
NIE
NIE
NIE
TAK
2 2
1 2
3 1
1 3
3 2
1 1
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
TAK
1 2
1 1
1 3
1 4
2 3
2 2
2 4
4 2
3 1
4 3
3 2
4 1
NIE
NIE
NIE
NIE
NIE
TAK
2 1
1 1
2 3
1 3
2 4
1 4
3 1
2 2
3 3
3 2
...

result:

ok correct (10000 test cases)

Test #3:

score: 0
Accepted
time: 68ms
memory: 3636kb

input:

10000
6 4
x.xx.o
xo.o.x
ooox.o
o..xo.
..xxxo
o.oxx.
6 5
oooxxx
oxoxxo
xoooxo
xoxxxx
xooxox
xoxxxx
6 3
o.x.x.
oo.o.x
xx.oo.
.x.xx.
ooxo..
.xxo..
6 6
xoo..o
o.xx.x
oooooo
xx.x..
o..xx.
...xxx
6 5
xooxoo
ooxxoo
xxooxx
oxooxx
oxoxxx
xxoxoo
6 5
xoxxxo
ooooxo
ooxoxx
oxxoox
xxxxox
ooooxo
6 5
o....o
.ox.oo
...

output:

TAK
1 6
1 1
2 2
1 3
2 4
1 4
3 1
2 1
3 2
2 6
3 3
4 4
3 6
5 3
4 1
5 4
4 5
5 5
5 6
6 4
6 1
6 5
6 3
3 4
NIE
TAK
1 3
1 1
1 5
2 1
2 6
2 2
3 1
2 4
3 2
3 4
4 2
3 5
4 4
5 1
4 5
5 2
6 2
5 4
6 3
6 4
5 3
NIE
TAK
1 2
1 1
1 3
1 4
1 5
2 3
1 6
2 4
2 1
3 1
2 2
3 2
2 5
3 5
2 6
3 6
3 3
4 2
3 4
4 5
4 1
4 6
4 3
5 2
4 4
...

result:

ok correct (10000 test cases)