QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#270431#5509. Kooky Tic-Tac-Toepooty#AC ✓29ms3484kbC++143.4kb2023-11-30 20:56:422023-11-30 20:56:42

Judging History

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

  • [2023-11-30 20:56:42]
  • 评测
  • 测评结果:AC
  • 用时:29ms
  • 内存:3484kb
  • [2023-11-30 20:56:42]
  • 提交

answer

#ifdef MY_LOCAL
#include "D://competitive_programming/debug/debug.h"
#define debug(x) cerr << "[" << #x<< "]:"<<x<<"\n"
#else
#define debug(x) 
#endif
#define REP(i, n) for(int i = 0; i < (n); i ++)
#define REPL(i,m, n) for(int i = (m); i < (n); i ++)
#define SORT(arr) sort(arr.begin(), arr.end())
#define LSOne(S) ((S)&-(S))
#define sz(X) ((int)X.size())
#define READ(arr) for(auto &a: arr){cin>>a;}
#define SUM(arr) accumulate((arr).begin(), (arr).end(), 0LL)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef tree<int,null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> ost;
const ll INF = 1e18;

void solve() {
	int n,k;cin>>n>>k;
	vector<string> vec(n);
	READ(vec);

	auto getseq = [&](vector<string> vec, int first1) {
		vii vec1;
		vii vec2;
		REP(i, n) {
			REP(j, n) {
				if (vec[i][j] == 'o') {
					vec1.push_back({i,j});
				} else if (vec[i][j] == 'x') {
					vec2.push_back({i,j});
				} else {}
			}
		}

		vii farr;
		int which = first1;
		int pt1 = 0;
		int pt2 = 0;
		while(pt1 != sz(vec1) || pt2 != sz(vec2)) {
			if (which == 1) {
				// pt2..
				farr.push_back(vec2[pt2++]);
			} else {
				farr.push_back(vec1[pt1++]);
			}
			which =  1 - which;
		}
		return farr;
	};
	auto not_end = [&](vector<string> tosee) {
		vi vdir = {0,1,1,1};
		vi udir = {1,1,0,-1};
		REP(i, n) {
			REP(j, n) {
				if (tosee[i][j] == '.') continue;
				REP(dir, 4) {
					bool good = true;
					REP(kk, k) {
						int ni = i + vdir[dir]*kk;
						int nj = j + udir[dir]*kk;
						if (ni < 0 || ni >= n || nj < 0 || nj >= n) {
							good = false;break;
						} 
						if (tosee[ni][nj] != tosee[i][j]) {
							good = false;break;
						}
					}
					if (good) {
						return false;
					}
				}
				// try all directions..
			}
		}
		return true;
	};
	auto printans = [&](vii &farr) {
		cout<<"TAK\n";
		for (auto [x,y]: farr) {
			cout<<x+1<<" "<<y+1<<"\n";
		}
		return;
	};
	int ct1 = 0;
	int ct2 = 0;
	REP(i, n) {
		REP(j, n) {
			if (vec[i][j] == 'x') {
				ct2++;
			} else if (vec[i][j] == 'o') {
				ct1++;
			} else {

			}
		}
	}
	if (abs(ct1 - ct2) > 1) {
		cout<<"NIE\n";return;
	}
	if (not_end(vec)) {
		if (ct1 + ct2 != n*n) {
			cout<<"NIE\n";
		} else {
			vii farr;
			if (ct1 > ct2) {
				farr = getseq(vec, 0);
			} else {
				farr = getseq(vec, 1);
			}
			printans(farr);
		}return;
	}
	//debug("here!");
	REP(i, n) {
		REP(j, n) {
			if (vec[i][j] == '.') continue;
			if (ct1 >= ct2 && vec[i][j] == 'o') {
				//debug("bo!");
				vector<string> temp = vec;
				temp[i][j] = '.';
				if (not_end(temp)) {
					vii f1 = getseq(temp, ct1 > ct2 ? 0 : 1);
					f1.push_back({i,j});
					printans(f1);return;
				}
			} 
			if (ct2 >= ct1 && vec[i][j] == 'x') {
				//debug("ho!");
				vector<string> temp = vec;
				temp[i][j] = '.';
				if (not_end(temp)) {
					//debug(temp);
					vii f1 = getseq(temp, ct2 > ct1 ? 1 : 0);
					f1.push_back({i,j});
					printans(f1);return;
				}
			}
		}
	}
	cout<<"NIE\n";
	

}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); 
	int tc;
	cin>>tc;
	REP(i, tc) {
		solve();
	}

}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
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 1
3 3
1 2
4 2
1 4
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: 11ms
memory: 3480kb

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

result:

ok correct (10000 test cases)

Test #3:

score: 0
Accepted
time: 29ms
memory: 3484kb

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