QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#234897 | #5509. Kooky Tic-Tac-Toe | raztun# | WA | 1ms | 3420kb | C++20 | 3.6kb | 2023-11-02 01:44:37 | 2023-11-02 01:44:37 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
char tab[10][10];
int w[10][10];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int zz; cin>>zz;
while (zz--)
{
int n, k; cin>>n>>k;
int a=0, b=0, mx=0, whx=-1, why=-1;
vector<pair<int, int>>xx, oo;
for (int i=0; i<n; i++)
{
for (int j=0; j<n; j++)
{
cin>>tab[i][j];
if (tab[i][j]=='x') xx.push_back({i, j}), a++;
if (tab[i][j]=='o') oo.push_back({i, j}), b++;
w[i][j]=0;
}
}
if (abs(a-b) > 1)
{
cout<<"NIE\n";
continue;
}
int wa=0, wb=0;
for (int i=0; i<n; i++)
{
for (int j=0; j<n; j++)
{
if (tab[i][j]=='.') continue;
int x=i, y=j, cnt=0;
while (cnt<k && x>=0 && tab[i][j]==tab[x][y]) x--, cnt++;
if (cnt==k)
{
wa+=tab[i][j]=='x';
wb+=tab[i][j]=='o';
x=i; y=j;
while (cnt>0 && x>=0) w[x][y]++, x--, cnt--;
}
x=i; y=j; cnt=0;
while (cnt<k && y>=0 && tab[i][j]==tab[x][y]) y--, cnt++;
if (cnt==k)
{
wa+=tab[i][j]=='x';
wb+=tab[i][j]=='o';
x=i; y=j;
while (cnt>0 && y>=0) w[x][y]++, y--, cnt--;
}
x=i; y=j; cnt=0;
while (cnt<k && x>=0 && y>=0 && tab[i][j]==tab[x][y]) x--, y--, cnt++;
if (cnt==k)
{
wa+=tab[i][j]=='x';
wb+=tab[i][j]=='o';
x=i; y=j;
while (cnt>0 && x>=0 && y>=0) w[x][y]++, x--, y--, cnt--;
}
x=i; y=j; cnt=0;
while (cnt<k && x>=0 && y<n && tab[i][j]==tab[x][y]) x--, y++, cnt++;
if (cnt==k)
{
wa+=tab[i][j]=='x';
wb+=tab[i][j]=='o';
x=i; y=j;
while (cnt>0 && x>=0 && y<n) w[x][y]++, x--, y++, cnt--;
}
}
}
for (int i=0; i<n; i++) for (int j=0; j<n; j++) if (w[i][j]>mx) {mx=w[i][j], whx=i, why=j;}
if ((!wa && !wb && a+b<n*n) || (wa && wb) || (wa && a<b) || (wb && b<a))
{
cout<<"NIE\n";
continue;
}
tab[whx][why]='.';
wa=wb=0;
for (int i=0; i<n; i++)
{
for (int j=0; j<n; j++)
{
if (tab[i][j]=='.') continue;
int na=0, nb=0;
int x=i, y=j, cnt=0;
while (x>=0 && tab[i][j]==tab[x][y]) x--, cnt++;
na+=(cnt>=k && tab[i][j]=='x');
nb+=(cnt>=k && tab[i][j]=='o');
x=i; y=j; cnt=0;
while (y>=0 && tab[i][j]==tab[x][y]) y--, cnt++;
na+=(cnt>=k && tab[i][j]=='x');
nb+=(cnt>=k && tab[i][j]=='o');
x=i; y=j; cnt=0;
while (x>=0 && y>=0 && tab[i][j]==tab[x][y]) x--, y--, cnt++;
na+=(cnt>=k && tab[i][j]=='x');
nb+=(cnt>=k && tab[i][j]=='o');
x=i; y=j; cnt=0;
while (x>=0 && y<n && tab[i][j]==tab[x][y]) x--, y++, cnt++;
na+=(cnt>=k && tab[i][j]=='x');
nb+=(cnt>=k && tab[i][j]=='o');
w[i][j]=na+nb;
if (w[i][j] >= mx)
{
mx=w[i][j];
whx=i;
why=j;
}
wa+=na;
wb+=nb;
}
}
if (wa || wb)
{
cout<<"NIE\n";
continue;
}
cout<<"TAK\n";
int kto=((a>b || (a==b && wb))? 1 : 2);
while (xx.size() || oo.size())
{
//~ cout<<zz<<" "<<xx.size()<<" "<<oo.size()<<endl;
if (kto == 1)
{
if (xx.back().first==whx && xx.back().second==why)
{
swap(xx[0], xx.back());
}
cout<<xx.back().first+1<<" "<<xx.back().second+1<<"\n";
xx.pop_back();
kto=2;
}
else if (kto == 2)
{
if (oo.back().first==whx && oo.back().second==why)
{
swap(oo[0], oo.back());
}
cout<<oo.back().first+1<<" "<<oo.back().second+1<<"\n";
oo.pop_back();
kto=1;
}
}
}
}
//~ 1
//~ 4 3
//~ xxxx
//~ o.o.
//~ ....
//~ o.o.
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3420kb
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 4 2 1 4 3 3 1 2 2 4 1 1 TAK 1 2 3 1 3 2 2 3 2 1 2 2 1 3 1 1 3 3 NIE NIE NIE NIE
result:
wrong answer Contestant's solution makes an incorrect last move (test case 2)