QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#77068#5509. Kooky Tic-Tac-ToeHe_RenAC ✓39ms3540kbC++232.4kb2023-02-13 01:06:022023-02-13 01:06:04

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-13 01:06:04]
  • 评测
  • 测评结果:AC
  • 用时:39ms
  • 内存:3540kb
  • [2023-02-13 01:06:02]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 6 + 5;

int n,d;
char s[MAXN][MAXN];

int iswin(char c)
{
	int cnt = 0;
	for(int i=1; i<=n; ++i)
		for(int j=1; j<=n; ++j)
			if(s[i][j] == c)
			{
				++cnt;
				if(i+d-1 <= n)
				{
					bool flag = 1;
					for(int k=0; k<d && flag; ++k)
						flag &= s[i+k][j] == c;
					if(flag) return -1;
				}
				if(j+d-1 <= n)
				{
					bool flag = 1;
					for(int k=0; k<d && flag; ++k)
						flag &= s[i][j+k] == c;
					if(flag) return -1;
				}
				if(i+d-1 <= n && j+d-1 <= n)
				{
					bool flag = 1;
					for(int k=0; k<d && flag; ++k)
						flag &= s[i+k][j+k] == c;
					if(flag) return -1;
				}
				if(i+d-1 <= n && j-d+1 >= 1)
				{
					bool flag = 1;
					for(int k=0; k<d && flag; ++k)
						flag &= s[i+k][j-k] == c;
					if(flag) return -1;
				}
			}
	return cnt;
}

vector<pii> ans;

bool check(char c)
{
	if(iswin('o') == -1 || iswin('x') == -1)
		return 0;
	
	vector<pii> A, B;
	for(int i=1; i<=n; ++i)
		for(int j=1; j<=n; ++j)
		{
			if(s[i][j] == c) A.emplace_back(i, j);
			if(s[i][j] == (c ^ 'o' ^ 'x')) B.emplace_back(i, j);
		}
	
	int delta = (int)A.size() - (int)B.size();
	if(delta < 0 || delta > 1) return 0;
	
	ans.clear();
	for(int i=0; i<(int)B.size(); ++i)
		ans.emplace_back(A[i]), ans.emplace_back(B[i]);
	if(delta == 1)
		ans.emplace_back(A.back());
	
	return 1;
}

void solve(void)
{
	scanf("%d%d",&n,&d);
	for(int i=1; i<=n; ++i)
		scanf("%s",s[i]+1);
	
	int A = iswin('o'), B = iswin('x');
	
	bool flag = 1;
	for(int i=1; i<=n; ++i)
		for(int j=1; j<=n; ++j)
		{
			if(s[i][j] == '.')
			{
				flag = 0;
				continue;
			}
			
			if(A != -1 && s[i][j] == 'o') continue;
			if(B != -1 && s[i][j] == 'x') continue;
			
			char c = s[i][j];
			s[i][j] = '.';
			
			if(check(c ^ 'o' ^ 'x'))
			{
				reverse(ans.begin(), ans.end());
				ans.emplace_back(i, j);
				
				printf("TAK\n");
				for(auto t: ans)
					printf("%d %d\n",t.first,t.second);
				return;
			}
			
			s[i][j] = c;
		}
	
	if(flag)
	{
		if(check('x') || check('o'))
		{
			printf("TAK\n");
			for(auto t: ans)
				printf("%d %d\n",t.first,t.second);
			return;
		}
	}
	
	printf("NIE\n");
}

int main(void)
{
//	freopen("K.out","w",stdout);
	
	int T;
	scanf("%d",&T);
	while(T--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3540kb

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
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: 13ms
memory: 3460kb

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
1 2
1 1
1 3
2 2
2 1
2 3
3 2
3 1
3 3
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: 3540kb

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
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)