QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#129330#5509. Kooky Tic-Tac-ToeForever_Young#AC ✓190ms3740kbC++141.6kb2023-07-22 15:27:042023-07-22 15:27:08

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-22 15:27:08]
  • 评测
  • 测评结果:AC
  • 用时:190ms
  • 内存:3740kb
  • [2023-07-22 15:27:04]
  • 提交

answer

#include<bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
using namespace std;
int t,n,k,tot,head[2],tail[2],ed;
char ch[6][6];
pair<int,int> p[2][40],ep,w[4];
int endg(){
	int tmp=0;
	for (int i=0;i<n;i++)
	for (int j=0;j<n;j++)
	if (ch[i][j]!='.'){
		tmp+=1;
		for (int h=0;h<4;h++){
			int f=1;
			for (int kk=1;kk<k;kk++)
			if (i+kk*w[h].fi<0||i+kk*w[h].fi>=n||j+kk*w[h].se>=n||ch[i+kk*w[h].fi][j+kk*w[h].se]!=ch[i][j]){
				f=0;
				break;
			}
			if (f) return 1;
		}
	}
	if (tmp==n*n) return 2;
	return 0;
}
int check(){
	tot=0;
	tail[0]=tail[1]=0;
	ed=2;
	for (int i=0;i<n;i++)
	for (int j=0;j<n;j++)
	if (ch[i][j]!='.'){
		tot++;
		int typ;
		if (ch[i][j]=='x') typ=0;
		else if (ch[i][j]=='o') typ=1;
		p[typ][tail[typ]++]=mp(i,j);
		if (endg()){
			char tmp;
			tmp=ch[i][j];
			ch[i][j]='.';
			if (!endg()){
				ed=typ;
				ep=mp(i,j);
			}
			ch[i][j]=tmp;
		}
	}
	if (ed==2) return 2;
	//printf("%d %d\n",ep.fi,ep.se);
	for (int i=0;i<tail[ed];i++)
	if (p[ed][i]==ep) swap(p[ed][i],p[ed][tail[ed]-1]);
	if (endg()==2&&tail[ed]<tail[ed^1]) ed=ed^1;
	if (tail[ed]==tail[ed^1]) return ed^1;
	if (tail[ed]==tail[ed^1]+1) return ed;
	return 2;
}
int main(){
	//freopen("K.in","r",stdin);
	w[0]=mp(1,0);
	w[1]=mp(0,1);
	w[2]=mp(1,1);
	w[3]=mp(-1,1);
	scanf("%d",&t);
	while (t--){
		scanf("%d%d",&n,&k);
		for (int i=0;i<n;i++) scanf("%s",ch[i]);
		int f=check();
		if (f<2){
			printf("TAK\n");
			head[0]=head[1]=0;
			for (int i=0;i<tot;i++){
				printf("%d %d\n",p[f][head[f]].fi+1,p[f][head[f]].se+1);
				head[f]++;
				f^=1;
			}
		}
		else printf("NIE\n");
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3724kb

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: 16ms
memory: 3740kb

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
4 3
2 4
1 3
3 1
1 4
3 3
2 2
...

result:

ok correct (10000 test cases)

Test #3:

score: 0
Accepted
time: 190ms
memory: 3648kb

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 3
5 4
6 2
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)