QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#197425 | #5509. Kooky Tic-Tac-Toe | Alfeh | AC ✓ | 31ms | 3476kb | C++14 | 3.3kb | 2023-10-02 15:50:30 | 2023-10-02 15:50:30 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const int sz = 1e5 + 5, mod = 1e9 + 7;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t = 1; cin >> t;
while(t--) {
int n, k; cin >> n >> k;
std::vector<string> v(n);
for(int i = 0; i < n; i++) cin >> v[i];
int a = 0, b = 0;
int a1 = 0, b1 = 0;
auto f = [&](int i, int j, int x, int y) {
int crt = 0;
char cc = v[i][j];
while(i >= 0 && i < n && j >= 0 && j < n && v[i][j] == cc) {
crt++;
i += x;
j += y;
}
return crt;
};
std::vector<pair<int,int>> v1, v2;
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
if(v[i][j] == '.') continue;
if(v[i][j] == 'x') {
a++;
v1.push_back({i + 1, j + 1});
}
else {
b++;
v2.push_back({i + 1, j + 1});
}
int cnt = max({f(i, j, 1, 0), f(i, j, 0, 1),
f(i, j, 1, 1), f(i, j, 1, -1)});
if(cnt >= k) {
if(v[i][j] == 'x') a1++;
else b1++;
}
}
}
//cout << a << " " << b << " " << a1 << " " << b1 << "\n";
if(max(a, b) - min(a, b) > 1 || min(a1, b1) > 0 ||
(a + b != n * n && max(a1, b1) == 0)) {
cout << "NIE\n";
continue;
}
auto prin = [&]() {
if(v1.size() < v2.size()) swap(v1, v2);
cout << "TAK\n";
while(!v1.empty()) {
auto [a, b] = v1.back();
v1.pop_back();
cout << a << " " << b << "\n";
if(!v2.empty()) {
auto [a, b] = v2.back();
v2.pop_back();
cout << a << " " << b << "\n";
}
}
};
auto khali = [&]() {
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
if(v[i][j] == '.') continue;
int cnt = max({f(i, j, 1, 0), f(i, j, 0, 1),
f(i, j, 1, 1), f(i, j, 1, -1)});
if(cnt >= k) return 0;
}
}
return 1;
};
if(a1 > 0 || b1 > 0) {
if(b1) swap(v1, v2);
if(v1.size() < v2.size()) {
cout << "NIE\n";
continue;
}
int pos = 0;
for(int i = 0; i < v1.size(); i++) {
auto [a, b] = v1[i];
char cc = v[a - 1][b - 1];
v[a - 1][b - 1] = '.';
if(khali()) {
pos = 1;
swap(v1[0], v1[i]);
break;
}
v[a - 1][b - 1] = cc;
}
if(!pos) cout << "NIE\n";
else {
if(v1.size() == v2.size()) swap(v1, v2);
prin();
}
} else prin();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3436kb
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: 9ms
memory: 3476kb
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 1 1 2 3 2 2 1 3 1 4 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: 31ms
memory: 3476kb
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 1 1 3 2 2 6 3 1 2 1 2 4 1 4 2 2 1 3 1 6 3 4 NIE TAK 6 3 6 4 6 2 5 4 1 3 5 2 4 5 5 1 4 4 3 5 4 2 3 4 3 2 2 4 3 1 2 2 2 6 2 1 1 5 1 1 5 3 NIE TAK 6 4 6 6 6 2 6 5 6 1 6 3 5 6 5 3 5 5 5 1 5 4 4 4 5 2 4 3 4 6 4 1 4 5 3 4 4 2 3 3 3 6 2 6 3 5 2 5 3 2 ...
result:
ok correct (10000 test cases)