QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#546498 | #5509. Kooky Tic-Tac-Toe | Fika# | AC ✓ | 63ms | 3648kb | C++14 | 3.0kb | 2024-09-04 05:55:25 | 2024-09-04 05:55:25 |
Judging History
answer
#include<bits/stdc++.h>
#pragma GCC optimize ("Ofast")
using namespace std;
#define rep(i,a,b) for(ll i = a; i<b;i++)
#define rrep(i,a,b) for(ll i = b-1; i>=a;i--)
#define trav(x,a) for(auto &x: a)
#define all(v) v.begin(),v.end()
#define sz(v) ll(v.size())
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
ll n,k;
bool kInRow(vector<string> board, char c){
rep(i,0,n)
rep(j,0,n){
for(auto [dx,dy]:vector<pll>{{0,1},{1,0},{1,1},{-1,1}}){
bool all = true;
rep(l,0,k){
ll i1 = i+dx*l;
ll j1 = j+dy*l;
if(i1<0||i1>=n || j1>=n || board[i1][j1]!=c) all=false;
}
if(all) return true;
}
}
return false;
}
bool boardIsDraw(vector<string> board){
bool draw = true;
rep(i,0,n)
rep(j,0,n)
draw &= board[i][j]!='.';
return draw;
}
bool boardIsEnd(vector<string> board){
return kInRow(board,'x') || kInRow(board,'o') || boardIsDraw(board);
}
void solve(){
cin>>n>>k;
vector<string> board(n);
ll xs = 0;
ll os = 0;
rep(i,0,n) {
cin>>board[i];
rep(j,0,n){
xs += board[i][j]=='x';
os += board[i][j]=='o';
}
}
if(abs(xs-os)>1 || !boardIsEnd(board)) {
cout<<"NIE\n";
return;
}
vl potWinner;
if(xs>=os) potWinner.push_back('x');
if(xs<=os) potWinner.push_back('o');
for(auto wc: potWinner){
rep(i,0,n){
rep(j,0,n){
if(board[i][j]==wc){
vector<string> lastBoard = board;
lastBoard[i][j] = '.';
if(!boardIsEnd(lastBoard)){
bool oStart = (os+xs+(wc=='x'))%2;
vector<pll> oPos;
vector<pll> xPos;
rep(i2,0,n) rep(j2,0,n){
if(lastBoard[i2][j2]=='x') xPos.emplace_back(i2,j2);
if(lastBoard[i2][j2]=='o') oPos.emplace_back(i2,j2);
}
cout<<"TAK\n";
rep(i,0,os+xs-1){
if(i%2!=oStart){
cout<<oPos.back().first+1<<" "<<oPos.back().second+1<<"\n";
oPos.pop_back();
} else {
cout<<xPos.back().first+1<<" "<<xPos.back().second+1<<"\n";
xPos.pop_back();
}
}
cout<<i+1<<" "<<j+1<<"\n";
return;
}
}
}
}
}
cout<<"NIE\n";
}
int main(){
cin.tie(0);
ios_base::sync_with_stdio(0);
ll t; cin>>t;
while(t--) solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3572kb
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: 16ms
memory: 3640kb
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: 63ms
memory: 3648kb
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)