QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#89964 | #5509. Kooky Tic-Tac-Toe | installb# | AC ✓ | 401ms | 3584kb | C++20 | 2.8kb | 2023-03-21 21:20:42 | 2023-03-21 21:20:43 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2000005;
\
int win[2],a[10][10],n,k;
void calcwin(){
for(int i = 1;i <= n;i ++){
for(int j = 1;j <= n;j ++){
if(a[i][j]){
int flg = 1;
flg = 1; for(int l = 0;l < k;l ++) if(i + l > n || a[i + l][j] != a[i][j]) flg = 0;
if(flg) win[a[i][j]] = 1;
flg = 1; for(int l = 0;l < k;l ++) if(j + l > n || a[i][j + l] != a[i][j]) flg = 0;
if(flg) win[a[i][j]] = 1;
flg = 1; for(int l = 0;l < k;l ++) if(i + l > n || j + l > n || a[i + l][j + l] != a[i][j]) flg = 0;
if(flg) win[a[i][j]] = 1;
flg = 1; for(int l = 0;l < k;l ++) if(i + l > n || j - l < 1 || a[i + l][j - l] != a[i][j]) flg = 0;
if(flg) win[a[i][j]] = 1;
}
}
}
}
using pii = pair<int,int>;
vector<pii>ans;
int solve(int st){
ans.clear();
int now = st;
vector<pii>A[3];
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(a[i][j])A[a[i][j]].push_back(pii(i,j));
while(!A[now].empty()){
ans.push_back(A[now].back());
A[now].pop_back();
now=3-now;
}
if(!A[1].empty()||!A[2].empty())return -1;
return now;
}
int main(){
ios::sync_with_stdio(false);
int TC;
cin >> TC;
while(TC --){
cin >> n >> k;
memset(a,0,sizeof(a));
for(int i = 1;i <= n;i ++){
for(int j = 1;j <= n;j ++){
char ch; cin >> ch;
if(ch == 'o') a[i][j] = 1;
if(ch == 'x') a[i][j] = 2;
}
}
win[1]=win[2]=0;
calcwin();
if(!win[1]&&!win[2]){
bool flg = 1;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(a[i][j]==0)flg=0;
if(!flg){
puts("NIE");
continue;
}
}
bool flg = 0;
for(int c=1;!flg&&c<=2;c++){
for(int i=1;!flg&&i<=n;i++)
for(int j=1;!flg&&j<=n;j++)if(a[i][j]>0){
int last = a[i][j];
win[1]=win[2]=0;
a[i][j] = 0;
calcwin();
if(!win[1]&&!win[2]){
int id = solve(c);
if(id!=last);
else{
puts("TAK");
flg = 1;
for(auto &[x,y]: ans)printf("%d %d\n",x,y);
printf("%d %d\n",i,j);
}
}
a[i][j]=last;
}
}
if(!flg)puts("NIE");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3552kb
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 3 3 3 1 3 2 2 3 2 1 2 2 1 3 1 1 1 2 NIE NIE NIE NIE
result:
ok correct (7 test cases)
Test #2:
score: 0
Accepted
time: 29ms
memory: 3584kb
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 3 3 3 1 3 2 2 3 2 1 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 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: 401ms
memory: 3560kb
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 6 6 6 4 6 5 6 2 6 3 6 1 5 3 5 6 5 1 5 5 4 4 5 4 4 3 5 2 4 1 4 6 3 4 4 5 3 3 4 2 2 6 3 6 2 5 3 5 2 2 ...
result:
ok correct (10000 test cases)