QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#259832 | #5509. Kooky Tic-Tac-Toe | w4p3r# | AC ✓ | 106ms | 3440kb | C++20 | 3.1kb | 2023-11-21 14:51:14 | 2023-11-21 14:51:14 |
Judging History
answer
#include<bits/stdc++.h>
#define inf 1e9
#define eps 1e-6
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define REP(i,a,b) for(int i=a;i>=b;i--)
#define db double
#define ve vector<int>
#define pa pair<int,int>
#define fr first
#define sd second
#define pb push_back
#define mp make_pair
#define MEM(a) memset(a,0,sizeof(a))
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
inline ll read()
{
char ch = getchar();
ll s = 0, w = 1;
while (ch < '0' || ch > '9') {if (ch == '-')w = -1; ch = getchar();}
while (ch >= '0' && ch <= '9') {s = s * 10 + ch - '0'; ch = getchar();}
return s * w;
}
#define N 11
int n, k;
string s[N];
vector<pair<int, int>>ans;
void print()
{
cout << "TAK\n";
for (auto [x, y] : ans)cout << x << ' ' << y << '\n';
return ;
}
bool valid(int x, int y, char op) {return (x >= 1 && x <= n && y >= 1 && y <= n && s[x][y] == op);}
int ck(int x, int y)
{
char op = s[x][y];
int X[4] = {0, 1, 1, 1}, Y[4] = {1, 0, 1, -1};
for (int p = 0; p < 4; p ++)
{
for (int i = 0; i <= k - 1; i ++)
{
int flag = 1;
for (int j = 1; j <= i; j ++)
{
int tx = x + j * X[p], ty = y + j * Y[p];
if (!valid(tx, ty, op)) {flag = 0; break;}
}
if (!flag)continue;
for (int j = 1; j <= k - 1 - i; j ++)
{
int tx = x - j * X[p], ty = y - j * Y[p];
if (!valid(tx, ty, op)) {flag = 0; break;}
}
if (flag)return 1;
}
}
return 0;
}
int ck(int tg)
{
ans.clear();
int s0 = 0, s1 = 0;
vector<pair<int, int>>v0, v1;
// for (int i = 1; i <= n; i ++)cout << s[i] << '\n';
for (int i = 1; i <= n; i ++)
{
for (int j = 1; j <= n; j ++)
{
if (s[i][j] == 'o') {s0 ++, v0.push_back({i, j}); if (ck(i, j))return 0;}
if (s[i][j] == 'x') {s1 ++, v1.push_back({i, j}); if (ck(i, j))return 0;}
}
}
// cout << "PASS" << endl;
if (tg == 0) {if (s0 > s1 + 1 || s0 < s1)return 0;}
if (tg == 1) {if (s1 > s0 + 1 || s1 < s0)return 0;}
int now = tg;
while (v0.size() || v1.size())
{
if (now == 0)
{
if (v0.empty())return 0;
ans.push_back(v0.back()); v0.pop_back();
}
if (now == 1)
{
if (v1.empty())return 0;
ans.push_back(v1.back()); v1.pop_back();
}
now ^= 1;
}
return 1;
}
void sol()
{
cin >> n >> k;
int flag = 0;
for (int i = 1; i <= n; i ++)
{
cin >> s[i];
s[i] = '.' + s[i];
for (int j = 1; j <= n; j ++)flag |= (s[i][j] == '.');
}
if (!flag && ck(0)) {print(); return ;}
if (!flag && ck(1)) {print(); return ;}
for (int i = 1; i <= n; i ++)for (int j = 1; j <= n; j ++)if (s[i][j] != '.')
{
if (ck(i, j))
{
// cout << "??:" << i << ' ' << j << endl;
char op = s[i][j]; s[i][j] = '.';
if (ck(0) && s[ans.back().first][ans.back().second] != op) {ans.push_back({i, j}); print(); return ;}
if (ck(1) && s[ans.back().first][ans.back().second] != op) {ans.push_back({i, j}); print(); return ;}
s[i][j] = op;
}
}
cout << "NIE\n";
}
signed main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T; cin >> T;
while (T --)sol();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3404kb
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: 15ms
memory: 3408kb
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: 106ms
memory: 3440kb
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)