QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#583694 | #5509. Kooky Tic-Tac-Toe | ticking_away# | AC ✓ | 326ms | 3860kb | C++20 | 4.1kb | 2024-09-22 21:15:54 | 2024-09-22 21:15:55 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ui = unsigned int;
using ull = unsigned long long;
using ll = long long;
#define endl '\n'
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int maxn = 2e5 + 10;
const int mod = 1000000007;
#define inl inline
#define fr(i, a, b) for (int i = a; i <= b; i++)
#define ford(i, a, b) for (int i = a; i >= b; i--)
#define forall(i, a) for (auto &i : a)
/**
____ ___ _____
/ ___| _ _ / _ \___ /
\___ \| | | | | | ||_ \
___) | |_| | |_| |__) |
|____/ \__, |\___/____/
|___/
*/
istream &operator>>(istream &in, vector<int> &v)
{
for (auto &i : v)
in >> i;
return in;
}
ostream &operator<<(ostream &out, vector<int> &v)
{
for (auto &i : v)
out << i << " ";
return out;
}
bool _output = 1;
void solve()
{
int n, k;
cin >> n >> k;
vector<vector<int>> a(n + 1, vector<int>(n + 1));
vector<int> win(3);
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
char c;
cin >> c;
if (c == 'x')
a[i + 1][j + 1] = 2;
if (c == 'o')
a[i + 1][j + 1] = 1;
}
}
win[1] = win[2] = 0;
auto test_cal_win = [&]()
{
fr(i, 1, n)
{
fr(j, 1, n) if (a[i][j])
{
int f = 1;
f = 1;
fr(l, 0, k - 1) if (i + l > n || a[i + l][j] != a[i][j]) f = 0;
if (f)
win[a[i][j]] = 1;
f = 1;
fr(l, 0, k - 1) if (j + l > n || a[i][j + l] != a[i][j]) f = 0;
if (f)
win[a[i][j]] = 1;
f = 1;
fr(l, 0, k - 1) if (i + l > n || j + l > n || a[i + l][j + l] != a[i][j]) f = 0;
if (f)
win[a[i][j]] = 1;
f = 1;
fr(l, 0, k - 1) if (i + l > n || j - l < 1 || a[i + l][j - l] != a[i][j]) f = 0;
if (f)
win[a[i][j]] = 1;
}
}
};
test_cal_win();
if (!win[1] && !win[2]) // no win
{
bool f = 1;
fr(i, 1, n)
{
fr(j, 1, n)
{
if (a[i][j] == 0)
f = 0;
}
}
if (f == 0)
{
cout << "NIE" << endl;
return;
}
}
vector<pii> ans;
for (int c = 1; c <= 2; c++)
{
fr(i, 1, n)
fr(j, 1, n)
{
if (!a[i][j])
continue;
int last = a[i][j];
win[1] = win[2] = 0;
a[i][j] = 0;
test_cal_win();
auto make = [&](int now)
{
ans.clear();
vector<pii> b[3];
fr(i, 1, n)
{
fr(j, 1, n)
{
if (!a[i][j])
continue;
b[a[i][j]].push_back({i, j});
}
}
while (b[now].size())
{
ans.push_back(b[now].back());
b[now].pop_back();
now = 3 - now;
}
if (b[1].size() || b[2].size())
return -1;
return now;
};
if (!win[1] && !win[2])
{
int id = make(c);
if (id == last)
{
cout << "TAK" << endl;
for (auto [x, y] : ans)
cout << x << " " << y << endl;
cout << i << " " << j << endl;
return;
}
}
a[i][j] = last;
}
}
cout << "NIE" << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int _ = 1;
if (_output)
cin >> _;
while (_--)
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3612kb
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 2 3 3 3 2 2 3 1 1 1 1 3 2 1 TAK 1 4 4 2 1 2 3 3 1 1 2 4 TAK 3 3 3 1 3 2 2 3 2 1 2 2 1 3 1 1 1 2 NIE NIE NIE NIE
result:
ok correct (7 test cases)
Test #2:
score: 0
Accepted
time: 23ms
memory: 3860kb
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 2 3 3 3 2 2 3 1 1 1 1 3 2 1 TAK 3 3 3 1 3 2 2 3 2 1 2 2 1 3 1 1 1 2 NIE NIE NIE NIE NIE TAK 3 2 1 3 3 1 1 2 2 2 1 1 NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE NIE TAK 3 2 4 3 3 1 4 2 2 4 2 2 2 3 1 4 1 3 1 1 1 2 4 1 NIE NIE NIE NIE NIE TAK 4 4 4 3 4 1 4 2 3 4 3 2 3 3 2 2 3 1 1 4 ...
result:
ok correct (10000 test cases)
Test #3:
score: 0
Accepted
time: 326ms
memory: 3624kb
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 6 3 6 5 6 1 6 4 5 6 5 5 4 5 5 4 4 1 5 3 3 6 4 4 3 3 2 6 3 2 2 1 3 1 1 4 2 4 1 3 2 2 1 1 1 6 3 4 NIE TAK 6 3 6 4 6 2 5 4 4 5 5 2 4 4 5 1 4 2 3 5 3 2 3 4 3 1 2 4 2 6 2 2 1 5 2 1 1 3 1 1 5 3 NIE TAK 6 6 6 4 6 5 6 2 6 3 6 1 5 3 5 6 5 1 5 5 4 4 5 4 4 3 5 2 4 1 4 6 3 4 4 5 3 3 4 2 2 6 3 6 2 5 3 5 2 2 ...
result:
ok correct (10000 test cases)