QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#77758#5509. Kooky Tic-Tac-ToeXKErrorAC ✓39ms3784kbC++3.0kb2023-02-15 16:06:552023-02-15 16:06:57

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-15 16:06:57]
  • 评测
  • 测评结果:AC
  • 用时:39ms
  • 内存:3784kb
  • [2023-02-15 16:06:55]
  • 提交

answer

#include <bits/stdc++.h>

#define maxn 105

using namespace std;

int T;
int n, k;

char s[maxn][maxn];
int t[maxn][maxn];

int f[4][maxn][maxn];

bool check(int xi, int xj) {
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			if ((xi == i && xj == j) || s[i][j] == '.') {
				f[0][i][j] = f[1][i][j] = f[2][i][j] = f[3][i][j] = 0;
			}
			else if (s[i][j] == 'x') {
				f[0][i][j] = (s[i][j - 1] == 'x' ? f[0][i][j - 1] : 0) + 1;
				f[1][i][j] = (s[i - 1][j - 1] == 'x' ? f[1][i - 1][j - 1] : 0) + 1;
				f[2][i][j] = (s[i - 1][j] == 'x' ? f[2][i - 1][j] : 0) + 1;
				f[3][i][j] = (s[i - 1][j + 1] == 'x' ? f[3][i - 1][j + 1] : 0) + 1;
			}
			else if (s[i][j] == 'o') {
				f[0][i][j] = (s[i][j - 1] == 'o' ? f[0][i][j - 1] : 0) + 1;
				f[1][i][j] = (s[i - 1][j - 1] == 'o' ? f[1][i - 1][j - 1] : 0) + 1;
				f[2][i][j] = (s[i - 1][j] == 'o' ? f[2][i - 1][j] : 0) + 1;
				f[3][i][j] = (s[i - 1][j + 1] == 'o' ? f[3][i - 1][j + 1] : 0) + 1;
			}
//			cout<<f[0][i][j]<<" ";
			if (f[0][i][j] >= k || f[1][i][j] >= k || f[2][i][j] >= k || f[3][i][j] >= k) return 1;
		}
//		cout<<endl;
	}
	return 0;
}

int tot1;
pair<int, int> g1[maxn];
int tot2;
pair<int, int> g2[maxn];

int main() {
	int o = 0;
	scanf("%d", &T);
	while (T--) {
		++o;
		scanf("%d%d", &n, &k);
		for (int i = 0; i <= n + 1; i++) for (int j = 0; j <= n + 1; j++) s[i][j] = 0;
		for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
//		if (T > 72 && o == 72) {
//			printf("%d %d\n", n, k);
//			for (int i = 1; i <= n; i++) cout<<(s[i] + 1)<<endl;
//		}
		int cntx = 0, cnto = 0;
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				if (s[i][j] == 'x') ++cntx;
				if (s[i][j] == 'o') ++cnto;
			}
		}
		if (abs(cntx - cnto) > 1) {
			puts("NIE");
			continue;
		}
		if (cntx + cnto != n * n && !check(0, 0)) {
			puts("NIE");
			continue;
		}
		int sx = 0, sy = 0;
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				if (!check(i, j)) {
//					cout<<"F:"<<i<<" "<<j<<endl;
					if (s[i][j] == 'x' && abs(cntx - 1 - cnto) > 1) continue;
					if (s[i][j] == 'o' && abs(cntx - cnto + 1) > 1) continue;
					sx = i, sy = j;
					goto BK;
				}
			}
		}
		BK:;
		if (!sx) {
			puts("NIE");
			continue;
		}
		tot1 = tot2 = 0;
		char flg;
		if (cntx > cnto) flg = 'x';
		else if (cnto > cntx) flg = 'o';
		else flg = (s[sx][sy] == 'o' ? 'x' : 'o');
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) if (s[i][j] == flg && (i != sx || j != sy)) g1[++tot1] = {i, j};
		}
		if (flg == 'o') flg = 'x';
		else flg = 'o';
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) if (s[i][j] == flg && (i != sx || j != sy)) g2[++tot2] = {i, j};
		}
//		if (T < 72 || o == 72) {
		puts("TAK");
		for (int i = 1; tot1 || tot2; i ^= 1) {
			if (i == 1) printf("%d %d\n", g1[tot1].first, g1[tot1].second), --tot1;
			else printf("%d %d\n", g2[tot2].first, g2[tot2].second), --tot2;
		}
		printf("%d %d\n", sx, sy);
//		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3676kb

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: 12ms
memory: 3784kb

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: 39ms
memory: 3600kb

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)