QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#524014 | #5509. Kooky Tic-Tac-Toe | chimera | AC ✓ | 960ms | 10928kb | Python3 | 2.1kb | 2024-08-19 07:48:41 | 2024-08-19 07:48:41 |
Judging History
answer
Z = int(input())
for _ in range(Z):
N,K = list(map(int,input().split()))
Bd = [input() for _ in range(N)]
cX = "".join(Bd).count('x')
cO = "".join(Bd).count('o')
poses = {
'x': [],
'o': [],
'.': []
}
winseqs = []
for i in range(N):
for j in range(N):
poses[Bd[i][j]].append((i,j))
if Bd[i][j] not in 'xo': continue
for di,dj in ((1,0),(0,1),(1,-1),(1,1)):
ichk = i
jchk = j
seq = set([(i,j)])
for _ in range(K-1):
ichk += di
jchk += dj
if ichk < 0 or ichk >= N or jchk < 0 or jchk >= N:
break
if Bd[ichk][jchk] != Bd[i][j]:
break
seq.add((ichk, jchk))
else:
winseqs.append((Bd[i][j], seq))
if len(set(x for x,y in winseqs)) > 1:
print('NIE')
continue
if len(winseqs) == 0:
if cX + cO != N*N:
print('NIE')
continue
if cX > cO:
mode = 'x'
first = poses['x'][0]
else:
mode = 'o'
first = poses['o'][0]
else:
mode = list(set(x for x,y in winseqs))[0]
breakers = set.intersection(*(y for x,y in winseqs))
#print(winseqs)
if not len(breakers):
print('NIE')
continue
first = list(breakers)[0]
omode = 'o' if mode == 'x' else 'x'
if len(poses[mode]) < len(poses[omode]):
print('NIE')
continue
if len(poses[mode]) > len(poses[omode])+1:
print('NIE')
continue
out = []
out.append(first)
poses[mode].remove(first)
while len(poses[mode])+len(poses[omode]):
omode,mode=mode,omode
out.append(poses[mode].pop())
print('TAK')
for x,y in out[::-1]:
print(x+1,y+1)
详细
Test #1:
score: 100
Accepted
time: 6ms
memory: 10636kb
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 2 4 1 2 3 3 1 4 4 2 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: 0
Accepted
time: 247ms
memory: 10820kb
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 1 3 1 1 3 3 2 1 2 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 1 3 1 4 3 3 2 4 2 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:
ok correct (10000 test cases)
Test #3:
score: 0
Accepted
time: 960ms
memory: 10928kb
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 1 6 1 1 2 2 1 3 2 4 1 4 3 1 2 1 3 2 2 6 3 3 4 4 3 6 5 3 4 1 5 4 4 5 5 5 5 6 6 4 6 1 6 5 6 3 3 4 NIE TAK 1 3 1 1 1 5 2 1 2 6 2 2 3 1 2 4 3 2 3 4 4 2 3 5 4 4 5 1 4 5 5 2 6 2 5 4 6 3 6 4 5 3 NIE TAK 1 1 1 3 1 4 1 5 2 3 1 6 2 4 2 1 3 1 2 2 3 2 2 5 3 5 2 6 3 6 3 3 4 2 3 4 4 5 4 1 4 6 4 3 5 2 4 4 5 4 ...
result:
ok correct (10000 test cases)