QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#154674 | #5509. Kooky Tic-Tac-Toe | berarchegas# | AC ✓ | 54ms | 3868kb | C++17 | 4.4kb | 2023-08-31 20:59:06 | 2023-08-31 20:59:06 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1e9 + 7;
const int MAXN = 15;
const ll INF = 2e18;
char tb[MAXN][MAXN];
int n, k;
bool valid() {
int qtx = 0, qto = 0;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
if(tb[i][j] == 'x') qtx++;
if(tb[i][j] == 'o') qto++;
}
}
if(abs(qtx - qto) <= 1) return true;
return false;
}
bool finish() {
bool fs = false, qt = true;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
if(tb[i][j] == '.') {
qt = false;
continue;
}
bool th = true, tv = true, td = true, td1 = true;
for(int l = 0; l < k; l++) {
if(i + l > n || tb[i + l][j] != tb[i][j]) th = false;
if(j + l > n || tb[i][j + l] != tb[i][j]) tv = false;
if(i + l > n || j + l > n || tb[i + l][j + l] != tb[i][j]) td = false;
if(i + l > n || j - l < 1 || tb[i + l][j - l] != tb[i][j]) td1 = false;
}
if(th || tv || td || td1) fs = true;
}
}
if(qt) return true;
return fs;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while(t--) {
cin >> n >> k;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
cin >> tb[i][j];
}
}
if(!finish() || !valid()) {
cout << "NIE\n";
continue;
}
pii last = {0, 0};
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
char cur = tb[i][j];
if(cur == '.') continue;
tb[i][j] = '.';
if(!finish() && valid()) {
last = {i, j};
}
tb[i][j] = cur;
}
}
if(last.first == 0) {
cout << "NIE\n";
continue;
}
int ls = 0;
if(tb[last.first][last.second] == 'x') ls = 1;
vector <pii> vx, vo;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
if(i == last.first && j == last.second) continue;
if(tb[i][j] == 'x') vx.push_back({i, j});
else if(tb[i][j] == 'o') vo.push_back({i, j});
}
}
if(ls == 0) vo.push_back(last);
else vx.push_back(last);
int diff = vx.size() - vo.size(), sum = vx.size() + vo.size();
cout << "TAK\n";
if(diff == 0) {
if(ls == 0) {
for(int i = 0; i < sum; i++) {
int id = i / 2;
if(i % 2 == 0) {
cout << vx[id].first << ' ' << vx[id].second << '\n';
}
else {
cout << vo[id].first << ' ' << vo[id].second << '\n';
}
}
}
else {
for(int i = 0; i < sum; i++) {
int id = i / 2;
if(i % 2 == 0) {
cout << vo[id].first << ' ' << vo[id].second << '\n';
}
else {
cout << vx[id].first << ' ' << vx[id].second << '\n';
}
}
}
}
else {
if(ls == 1) {
for(int i = 0; i < sum; i++) {
int id = i / 2;
if(i % 2 == 0) {
cout << vx[id].first << ' ' << vx[id].second << '\n';
}
else {
cout << vo[id].first << ' ' << vo[id].second << '\n';
}
}
}
else {
for(int i = 0; i < sum; i++) {
int id = i / 2;
if(i % 2 == 0) {
cout << vo[id].first << ' ' << vo[id].second << '\n';
}
else {
cout << vx[id].first << ' ' << vx[id].second << '\n';
}
}
}
}
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3572kb
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 1 3 1 2 2 3 3 2 3 TAK 1 1 2 4 1 2 3 3 1 4 4 2 TAK 1 2 1 1 1 3 2 2 2 1 2 3 3 2 3 1 3 3 NIE NIE NIE NIE
result:
ok correct (7 test cases)
Test #2:
score: 0
Accepted
time: 8ms
memory: 3868kb
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 1 3 1 2 2 3 3 2 3 TAK 1 2 1 1 1 3 2 2 2 1 2 3 3 2 3 1 3 3 NIE NIE NIE NIE NIE TAK 2 2 1 1 3 1 1 2 3 2 1 3 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 1 3 1 4 2 3 2 4 3 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: 54ms
memory: 3840kb
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 3 4 3 6 4 4 4 1 5 3 4 5 5 4 5 6 5 5 6 1 6 5 6 3 6 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 1 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 ...
result:
ok correct (10000 test cases)