QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#77139#5509. Kooky Tic-Tac-ToeUCSC_Ravioli#RE 2ms3472kbC++204.2kb2023-02-13 05:13:272023-02-13 05:13:29

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 05:13:29]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:3472kb
  • [2023-02-13 05:13:27]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'

array<int,4> find_winner(vector<string> &v, int k, char c){
	int n = v.size();
	for(int i=0; i<n; i++){
		for(int j=0; j+k<=n; j++){
			// Check horizontal
			bool ok=1;
			for(int a=j; a<j+k; a++){
				ok &= (v[i][a] == c);
			}
			if(ok) return {i,j,0,1};
			// Check vertical
			ok=1;
			for(int a=j; a<j+k; a++){
				ok &= (v[a][i] == c);
			}
			if(ok) return {i,j,1,0};
		}
	}
	// Check diagonal
	for(int i=0; i+k<=n; i++){
		for(int j=0; j+k<=n; j++){
			bool ok=1;
			for(int a=0; a<k; a++){
				ok &= (v[i+a][j+a] == c);
			}
			if(ok) return {i,j,1,1};
		}
	}
	// Check anti-diagonal
	for(int i=0; i+k<=n; i++){
		for(int j=k-1; j<n; j++){
			bool ok=1;
			for(int a=0; a<k; a++){
				ok &= (v[i+a][j-a] == c);
			}
			if(ok) return {i,j,1,-1};
		}
	}
	return {-1,-1,-1,-1};
}

int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	int t;
	cin >> t;
	while(t--){
		int n, k;
		cin >> n >> k;
		vector<string> v(n);
		int numX=0, numO=0;
		for(auto &d:v){
			cin >> d;
			for(char c:d){
				if(c=='x') numX++;
				if(c=='o') numO++;
			}
		}
		array<int,4> x1 = find_winner(v,k,'x'), o1 = find_winner(v,k,'o');
		// cout << "x: " << x1[0] << ' ' << x1[1] << endl;
		// cout << "o: " << o1[0] << ' ' << o1[1] << endl;
		if(x1[0]==-1 && o1[0]==-1 && numX+numO == n*n){
			cout << "TAK\n";
			vector<array<int,2>> xs, os;
			for(int i=0; i<n; i++){
				for(int j=0; j<n; j++){
					if(v[i][j]=='x') xs.push_back({i,j});
					if(v[i][j]=='o') os.push_back({i,j});
				}
			}
			if(os.size() > xs.size()) swap(xs, os);
			for(int i=0; i<os.size(); i++){
				cout << xs[i][0]+1 << ' ' << xs[i][1]+1 << endl;
				cout << os[i][0]+1 << ' ' << os[i][1]+1 << endl;
			}
			if(xs.size() > os.size()){
				cout << end(xs)[-1][0]+1 << ' ' << end(xs)[-1][1]+1 << endl;
			}
			continue;
		}
		if((x1[0]==-1) == (o1[0]==-1)) {
			cout << "NIE\n";
			continue;
		}
		if(o1[0]==-1){
			if(numX != numO && numX != numO+1){
				cout << "NIE\n";
				continue;
			}
			auto [r,c,dx,dy] = x1;
			bool done=0;
			for(int z=0; z<k && !done; z++){
				assert(v[r][c]=='x');
				v[r][c]='.';
				array<int,4> x2 = find_winner(v,k,'x');
				if(x2[0]!=-1){
					v[r][c]='x';
					r+=dx;
					c+=dy;
					continue;
				}
				done=1;
				vector<array<int,2>> xs, os;
				for(int i=0; i<n; i++){
					for(int j=0; j<n; j++){
						if(v[i][j]=='x') xs.push_back({i,j});
						if(v[i][j]=='o') os.push_back({i,j});
					}
				}
				// cout << "os:\n";
				// for(auto &[r,c] : os){
					// cout << r << ' ' << c << endl;
				// }
				// cout << "xs:\n";
				// for(auto &[r,c] : xs){
					// cout << r << ' ' << c << endl;
				// }
				
				cout << "TAK\n";
				if(os.size() > xs.size()){
					cout << end(os)[-1][0]+1 << ' ' << end(os)[-1][1]+1 << endl;
					os.pop_back();
				}
				assert(os.size() == xs.size());
				for(int i=0; i<xs.size(); i++){
					cout << xs[i][0]+1 << ' ' << xs[i][1]+1 << endl;
					cout << os[i][0]+1 << ' ' << os[i][1]+1 << endl;
				}
				cout << r+1 << ' ' << c+1 << endl;
				break;
			}
			if(!done) cout << "NIE\n";
		}
		else{
			assert(x1[0]==-1);
			if(numX != numO && numX+1 != numO){
				cout << "NIE\n";
				continue;
			}
			auto [r,c,dx,dy] = o1;
			bool done=0;
			for(int z=0; z<k && !done; z++){
				assert(v[r][c]=='o');
				v[r][c]='.';
				array<int,4> o2 = find_winner(v,k,'o');
				if(o2[0]!=-1){
					v[r][c]='o';
					r+=dx;
					c+=dy;
					continue;
				}
				done=1;
				vector<array<int,2>> xs, os;
				for(int i=0; i<n; i++){
					for(int j=0; j<n; j++){
						if(v[i][j]=='x') xs.push_back({i,j});
						if(v[i][j]=='o') os.push_back({i,j});
					}
				}
				cout << "TAK\n";
				if(xs.size() > os.size()){
					cout << end(xs)[-1][0]+1 << ' ' << end(xs)[-1][1]+1 << endl;
					xs.pop_back();
				}
				assert(os.size() == xs.size());
				for(int i=0; i<xs.size(); i++){
					cout << os[i][0]+1 << ' ' << os[i][1]+1 << endl;
					cout << xs[i][0]+1 << ' ' << xs[i][1]+1 << endl;
				}
				cout << r+1 << ' ' << c+1 << endl;
				break;
			}
			if(!done) cout << "NIE\n";
		}
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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 2
3 1
2 3
3 3
2 1
TAK
1 4
3 3
1 1
4 2
1 2
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: -100
Dangerous Syscalls

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:


result: