QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#89882 | #5509. Kooky Tic-Tac-Toe | installb# | WA | 25ms | 3484kb | C++20 | 3.2kb | 2023-03-21 18:25:29 | 2023-03-21 18:25:33 |
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;
}
if(cnt[1] == 0 && cnt[2] == 0) cout << "TAK\n"; // ?
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3484kb
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 3 1 1 2 1 2 2 3 2 2 3 3 3 3 1 1 2 NIE NIE NIE NIE
result:
ok correct (7 test cases)
Test #2:
score: -100
Wrong Answer
time: 25ms
memory: 3344kb
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 3 1 1 2 1 2 2 3 2 2 3 3 3 3 1 1 2 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:
wrong output format Expected integer, but "NIE" found (test case 57)