QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#282441#5509. Kooky Tic-Tac-Toetkrawczyk#AC ✓41ms3520kbC++232.5kb2023-12-12 00:50:322023-12-12 00:50:33

Judging History

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

  • [2023-12-12 00:50:33]
  • 评测
  • 测评结果:AC
  • 用时:41ms
  • 内存:3520kb
  • [2023-12-12 00:50:32]
  • 提交

answer

#include <bits/stdc++.h>
#define st first
#define nd second 

using namespace std;

bool OK(vector<string>s, int n, int K)
{
	for(int j=0;j<n;j++) {  
		for(int i=0, same = 1;i<n;i++) {
			if(i and s[j][i] == s[j][i-1] and s[j][i] != '.')same++;
			else same = 1;
			if(K == same)return false;
		}
	}
	
	//cout << "jasne" << endl;
	for(int j=0;j<n;j++) {  
		for(int i=0, same = 1;i<n;i++) {
			if(i and s[i][j] == s[i-1][j] and s[i][j] != '.')same++;
			else same = 1;
			if(K == same)return false;
		}
	}

	//cout << "wow" << endl;
	for(int i=0;i<n;i++) {
		for(int j=0;j<n;j++) {
			if(s[j][i] == '.')continue;
			for(int k=0;k<K;k++) {
				if(i+k >= n or j+k >= n)break;
				if(s[j+k][i+k] != s[j][i])break;
				if(k == K-1)return false;
			}

			for(int k=0;k<K;k++) {
				if(i+k >= n or j-k < 0)break;
				if(s[j-k][i+k] != s[j][i])break;
				if(k == K-1)return false;
			}
		}
	}
	return true;
}

void solve() {
	int n, k;
	cin >> n >> k;

	vector<string>v(n);
	for(auto&x:v)cin>>x;
	
	int X=0, O=0;
	for(auto x:v)
		for(auto y:x)
			X+=(y=='x'),O+=(y=='o');
	if( X-O < -1 or 1 < X-O ) { 
		cout << "NIE\n";
		return;
	}

	if(OK(v,n,k) and O+X != n*n) {
		cout << "NIE\n";
		return;
	}

	pair<int,int>last = make_pair(-1,-1);
	if( X >= O ) {
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++) {
				if(v[i][j] != 'x')continue;
				auto temp = v;

				temp[i][j] = '.';
				if(OK(temp,n,k) && last.first == -1) {
					cout << "TAK\n";
					last = make_pair(i,j);
//					return;
				}
			}
	}
	
	if( X <= O ) {
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++) {
				if(v[i][j] != 'o')continue;
				auto temp = v;

				temp[i][j] = '.';
				if(OK(temp,n,k) && last.first == -1) {
					cout << "TAK\n";
					last = make_pair(i,j);
//					return;
				}
			}
	}
	if(last==make_pair(-1,-1)) {
		cout << "NIE\n";
		return;
	}

	stack<pair<int,int>>s;
	s.push(last);
	char wow = v[last.first][last.second];
	v[last.first][last.second] = '.';

	if(wow == 'x')X--;
	else O--;

	while(X + O)
	{
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
			{
				if(v[i][j] != wow and v[i][j] != '.')
				{
					s.push(make_pair(i,j));
					wow = v[i][j];
					v[i][j] = '.';
					
					if(wow == 'x')X--;
					else O--;
				}
			}
	}

	while(!s.empty()) {
		cout << s.top().first+1 << " " << s.top().second+1 << '\n';
		s.pop();
	}
	
	// cout << "NIE\n";
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	int t; cin >> t;
	while(t--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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
1 1
3 1
2 2
1 3
2 1
TAK
1 4
4 2
1 2
3 3
1 1
2 4
TAK
2 1
3 1
3 3
2 3
3 2
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: 3500kb

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

result:

ok correct (10000 test cases)

Test #3:

score: 0
Accepted
time: 41ms
memory: 3520kb

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
4 1
1 4
3 6
1 3
3 3
1 1
6 3
5 5
3 2
6 5
6 1
5 4
2 4
6 4
5 6
5 3
4 5
4 4
3 1
2 6
2 2
2 1
1 6
3 4
NIE
TAK
4 5
5 4
3 2
2 4
6 3
5 2
4 4
3 5
3 1
2 2
1 5
6 4
6 2
5 1
4 2
3 4
2 6
2 1
1 3
1 1
5 3
NIE
TAK
2 2
6 2
2 1
6 1
1 6
5 6
1 3
5 5
6 6
4 6
4 4
3 6
3 4
3 2
2 6
2 4
6 5
6 4
6 3
5 4
5 3
5 2
5 1
4 5
4 3
...

result:

ok correct (10000 test cases)