QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#78098#5509. Kooky Tic-Tac-ToexzyWA 11ms3452kbC++203.9kb2023-02-16 18:31:522023-02-16 18:31:54

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-16 18:31:54]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:3452kb
  • [2023-02-16 18:31:52]
  • 提交

answer

#include <bits/stdc++.h>
using ll = long long;
using namespace std;

void solve() {
    int n, k; cin >> n >> k;
    vector<string> grid(n);
    for (auto& x : grid) cin >> x;

    auto check_down = [&](int i, int j, char player) {
        for (int row = i; row < i + k; ++row) {
            if (row >= n || grid[row][j] != player) return false;
        }
        return true;
    };
    auto check_right = [&](int i, int j, char player) {
        for (int col = j; col < j + k; ++col) {
            if (col >= n || grid[i][col] != player) return false;
        }
        return true;
    };
    auto check_diag_down = [&](int i, int j, char player) {
        for (int diag = 0; diag < k; ++diag) {
            if (i + diag >= n || j + diag >= n || grid[i + diag][j + diag] != player) return false;
        }
        return true;
    };
    auto check_diag_up= [&](int i, int j, char player) {
        for (int diag = 0; diag < k; ++diag) {
            if (i - diag < 0 || j + diag >= n || grid[i - diag][j + diag] != player) return false;
        }
        return true;
    };

    array<vector<pair<int, int>>, 2> pos{};
    for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) {
        if (grid[i][j] == 'x') pos[0].emplace_back(i, j);
        if (grid[i][j] == 'o') pos[1].emplace_back(i, j);
    }
    if (abs(int(pos[1].size()) - int(pos[0].size())) > 1) {
        cout << "NIE\n";
        return;
    }
    pair<int, int> last_pos = {-1, -1};
    for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) if (grid[i][j] != '.') {
        if (grid[i][j] == '.') continue;
        if (check_diag_down(i, j, grid[i][j])) {
            if (last_pos.first != -1) {
                cout << "NIE\n";
                return;
            }
            last_pos = {i, j};
        }
        if (check_diag_up(i, j, grid[i][j])) {
            if (last_pos.first != -1) {
                cout << "NIE\n";
                return;
            }
            last_pos = {i, j};
        }
        if (check_down(i, j, grid[i][j])) {
            if (last_pos.first != -1) {
                cout << "NIE\n";
                return;
            }
            last_pos = {i, j};
        }
        if (check_right(i, j, grid[i][j])) {
            if (last_pos.first != -1) {
                cout << "NIE\n";
                return;
            }
            last_pos = {i, j};
        }
    }
    auto print_turns = [&](int first) {
        cout << "TAK\n";
        int y = 0;
        for (int x = 0; x < pos[first].size(); ++x) {
            cout << pos[first][x].first + 1 << ' ' << pos[first][x].second + 1<< '\n';
            if (y < pos[1 - first].size()) {
                cout << pos[1 - first][y].first + 1 << ' ' << pos[1 - first][y].second + 1<< '\n';
                y++;
            }
        }
        if (y < pos[1 - first].size()) {
            cout << pos[1 - first][y].first + 1 << ' ' << pos[1 - first][y].second + 1<< '\n';
            y++;
        }
        assert(y == pos[1 - first].size());
    };
    if (last_pos.first == -1) {
        if (pos[0].size() + pos[1].size() != n * n) {
            cout << "NIE\n";
            return;
        }
        print_turns((pos[0].size() > pos[1].size()? 0 : 1));
        return;
    }
    assert(grid[last_pos.first][last_pos.second] != '.');
    int first_turn;
    int last_move = (grid[last_pos.first][last_pos.second] == 'x' ? 0 : 1);
    {
        if (pos[last_move].size() > pos[1 - last_move].size()) first_turn = last_move;
        else if (pos[last_move].size() == pos[1 - last_move].size()) first_turn = 1 - last_move;
        else {
            cout << "NIE\n";
            return;
        }
    }
    pos[last_move].erase(std::remove(pos[last_move].begin(), pos[last_move].end(), last_pos));
    print_turns(first_turn);
    cout << last_pos.first + 1 << ' ' << last_pos.second + 1<< '\n';
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int t = 1; cin >> t;
    while (t--) solve();
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 3452kb

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
2 4
1 2
3 3
1 4
4 2
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: -100
Wrong Answer
time: 11ms
memory: 3388kb

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
NIE
NIE
NIE
NIE
TAK
1 2
1 1
2 2
3 2
2 3
3 3
...

result:

wrong answer Jury claims solution exists, contestant claims it does not (test case 31)