QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#197396 | #5509. Kooky Tic-Tac-Toe | Alfeh | WA | 8ms | 3604kb | C++14 | 3.3kb | 2023-10-02 15:25:59 | 2023-10-02 15:26:01 |
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) a += 1234;
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3568kb
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: -100
Wrong Answer
time: 8ms
memory: 3604kb
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:
wrong answer Jury claims solution exists, contestant claims it does not (test case 334)