QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#89900 | #5509. Kooky Tic-Tac-Toe | installb# | WA | 2ms | 3356kb | C++20 | 3.1kb | 2023-03-21 18:50:00 | 2023-03-21 18:50:01 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2000005;
vector <pair <int,int> > vec[6];
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;
}
}
}
}
void solve(int id){
for(int i = 0;i <= 2;i ++) vec[i].clear();
for(int i = 1;i <= n;i ++){
for(int j = 1;j <= n;j ++){
vec[a[i][j]].push_back(make_pair(i,j));
}
}
for(int i = 0;i < vec[3 - id].size();i ++){
cout << vec[id][i].first << ' ' << vec[id][i].second << '\n';
cout << vec[3 - id][i].first << ' ' << vec[3 - id][i].second << '\n';
}
if(vec[id].size() > vec[3 - id].size()) cout << vec[id][vec[id].size() - 1].first << ' ' << vec[id][vec[id].size() - 1].second << '\n';
}
int main(){
ios::sync_with_stdio(false);
int TC;
cin >> TC;
while(TC --){
int cnt[3] = {0};
cin >> n >> k;
for(int i = 1;i <= n;i ++){
for(int j = 1;j <= n;j ++){
char ch; cin >> ch;
a[i][j] = 0;
if(ch == 'o') a[i][j] = 1,cnt[1] ++;
if(ch == 'x') a[i][j] = 2,cnt[2] ++;
}
}
win[1] = win[2] = 0;
calcwin();
// cout << cnt[1] << ' ' << cnt[2] << ' ' << win[1] << ' ' << win[2] << endl;
if((win[1] && win[2]) || abs(cnt[2] - cnt[1]) > 1 || (!win[1] && !win[2] && cnt[1] + cnt[2] < n * n)){
// both win, wrong step, nobody win but not end
cout << "NIE\n";
continue;
}
int flg = 0,cur = (win[1] ? 1 : 2);
if(!win[1] && !win[2]) cur = (cnt[1] > cnt[2] ? 1 : 2);
if(win[cur] && cnt[cur] < cnt[3 - cur]){
cout << "NIE\n";
continue;
}
for(int i = 1;i <= n;i ++){
for(int j = 1;j <= n;j ++){
if(a[i][j] == cur){
a[i][j] = 0;
win[1] = win[2] = 0;
calcwin();
if(!win[1] && !win[2]){
cout << "TAK\n";
flg = 1; solve(cnt[cur] == cnt[3 - cur] ? 3 - cur : cur);
cout << i << ' ' << j << '\n';
break;
}
a[i][j] = cur;
}
}
if(flg) break;
}
cout << "NIE\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 3356kb
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 NIE TAK 1 1 3 3 1 2 4 2 1 4 2 4 NIE TAK 1 3 1 1 2 1 2 2 3 2 2 3 3 3 3 1 1 2 NIE NIE NIE NIE NIE
result:
wrong answer Jury claims solution exists, contestant claims it does not (test case 2)