QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#93587#5509. Kooky Tic-Tac-ToeHCPS42#AC ✓37ms3500kbC++176.2kb2023-04-01 18:02:562023-04-01 18:03:00

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-01 18:03:00]
  • 评测
  • 测评结果:AC
  • 用时:37ms
  • 内存:3500kb
  • [2023-04-01 18:02:56]
  • 提交

answer

#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <algorithm>
#include <cassert>
#include <chrono>
#include <random>
#include <string>
#include <numeric>
#include <complex>
#include <tuple>
#include <utility>
#include <bitset>
#include <array>
#include <stack>
#include <sstream>
using namespace std;
typedef long long ll;
 
string to_string(string a) { return '"' + a + '"'; }
string to_string(const char* a) { return to_string((string) a); }
string to_string(bool a) { return a ? "true" : "false"; }
template <class T1, class T2>
string to_string(pair<T1, T2> a) {
    return "(" + to_string(a.first) + ", " + to_string(a.second) + ")";
}
template <class T>
string to_string(T a) {
    bool first = true; string res = "{";
    for (const auto& i : a) {
        if (!first) res += ", ";
        first = false;
        res += to_string(i);
    }
    res += "}";
    return res;
}
void debug_out() { cerr << endl; }
template <class T1, class... T2>
void debug_out(T1 a, T2... b) {
    cerr << " " << to_string(a);
    debug_out(b...);
}
 
#ifdef LOCAL
#define out(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define out(...) 42
#endif

clock_t start_time; void start_timer() { start_time = clock(); }
double get_time() { return (double) (clock() - start_time) / CLOCKS_PER_SEC; }

void Solve();

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
    freopen("usr/share/man/man1/input.txt", "r", stdin);
#endif
    start_timer();
    Solve();
#ifdef LOCAL
    cerr << fixed << setprecision(3);
    cerr << endl << "Time spent: " << get_time() << endl;
#endif
    return 0;
}

// do something, stay focused
// look for stupid bugs
// guess, slow, stress
// don't overgeneralize
// don't rush

// don't waste time on standings

// SOLVE THE PROBLEM OR DIE TRYING
// THE SOLUTION IS ALWAYS SIMPLE
// THE CODE IS ALWAYS SHORT

// DON'T BACK DOWN
// STAND YOUR GROUND

// IT'S NOT POSSIBLE
// NO, IT'S NECESSARY

const int N = 10;

char a[N][N];
int n, k;

bool win() {
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (a[i][j] == '.') continue;
            if (j + k - 1 <= n) {
                bool ok = 1;
                for (int J = j; J <= j + k - 1; J++) {
                    if (a[i][J] != a[i][j]) ok = 0;
                }
                if (ok) return 1;
            }
            if (i + k - 1 <= n) {
                bool ok = 1;
                for (int I = i; I <= i + k - 1; I++) {
                    if (a[I][j] != a[i][j]) ok = 0;
                }
                if (ok) return 1;
            }
            if (i + k - 1 <= n && j + k - 1 <= n) {
                bool ok = 1;
                for (int x = 0; x <= k - 1; x++) {
                    if (a[i + x][j + x] != a[i][j]) ok = 0;
                }
                if (ok) return 1;
            }
            if (i + k - 1 <= n && j - k + 1 >= 1) {
                bool ok = 1;
                for (int x = 0; x <= k - 1; x++) {
                    if (a[i + x][j - x] != a[i][j]) ok = 0;
                }
                if (ok) return 1;
            }
        }
    }
    return 0;
}

vector<pair<int, int>> sol() {
    int tot = 0;
    int cro_cnt = 0;
    int cir_cnt = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (a[i][j] != '.') tot++;
            if (a[i][j] == 'x') cro_cnt++;
            if (a[i][j] == 'o') cir_cnt++;
        }
    }
    if (tot == 0 || abs(cro_cnt - cir_cnt) > 1) {
        return {};
    }
    vector<pair<int, int>> res;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (a[i][j] == '.') continue;
            char c = a[i][j];
            if (c == 'x' && !(cro_cnt - 1 <= cir_cnt && cir_cnt <= cro_cnt)) continue;
            if (c == 'o' && !(cir_cnt - 1 <= cro_cnt && cro_cnt <= cir_cnt)) continue;
            if (tot < n * n && !win()) continue;
            a[i][j] = '.';
            if (win()) {
                a[i][j] = c;
                continue;
            }
            a[i][j] = c;
            res.push_back({i, j});
            vector<pair<int, int>> cro;
            vector<pair<int, int>> cir;
            for (int I = 1; I <= n; I++) {
                for (int J = 1; J <= n; J++) {
                    if (i == I && j == J) continue;
                    if (a[I][J] == 'x') cro.push_back({I, J});
                    if (a[I][J] == 'o') cir.push_back({I, J});
                }
            }
            for (int i = 1; i < tot; i++) {
                if (i & 1) {
                    if (c == 'x') {
                        assert(!cir.empty());
                        res.push_back(cir.back());
                        cir.pop_back();
                    }
                    else {
                        assert(!cro.empty());
                        res.push_back(cro.back());
                        cro.pop_back();
                    }
                }
                else {
                    if (c == 'x') {
                        assert(!cro.empty());
                        res.push_back(cro.back());
                        cro.pop_back();
                    }
                    else {
                        assert(!cir.empty());
                        res.push_back(cir.back());
                        cir.pop_back();
                    }
                }
            }
            reverse(res.begin(), res.end());
            return res;
        }
    }
    return res;
}

void Solve() {
    int T;
    cin >> T;
    while (T--) {
        cin >> n >> k;
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                cin >> a[i][j];
            }
        }
        auto ans = sol();
        if (ans.empty()) {
            cout << "NIE\n";
        }
        else {
            cout << "TAK\n";
            for (auto [i, j] : ans) {
                cout << i << " " << j << "\n";
            }
        }
    }
}

详细

Test #1:

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

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

result:

ok correct (7 test cases)

Test #2:

score: 0
Accepted
time: 13ms
memory: 3440kb

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 3
1 1
2 1
2 2
3 2
2 3
3 3
3 1
1 2
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: 37ms
memory: 3500kb

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 4
1 3
2 3
1 5
2 4
1 6
3 1
2 1
3 2
2 2
3 5
2 5
3 6
2 6
4 2
3 3
4 5
3 4
4 6
4 1
5 2
4 3
5 4
4 4
...

result:

ok correct (10000 test cases)