11760 | 2024-11-09 15:24:37 | balint | Stefan sakkmesteri ambíciói | python3 | Runtime error 0/100 | 18ms | 3728 KiB |
from sys import stdin
def main():
for _ in range(int(input())):
board = stdin.read(9 * 8).splitlines()
# search black queen position
brk = False
for y in range(8):
for x in range(8):
if board[y][x] == "q":
brk = True
break
if brk:
break
board_checked = False
# left
i = x - 1
while i >= 0:
if board[y][i] != ".":
if board[y][i] in [
"Q",
"R",
]: # can only be hit from left side if its a rook or queen
print("YES")
board_checked = True
break # continue bc piece blocks attacks from this direction
i -= 1
if board_checked:
continue
# right
i = x + 1
while i < 8:
if board[y][i] != ".":
if board[y][i] in [
"Q",
"R",
]: # can only be hit from right side if its a rook or queen
print("YES")
board_checked = True
break # continue bc piece blocks attacks from this direction
i += 1
if board_checked:
continue
# up
i = y - 1
while i >= 0:
if board[i][x] != ".":
if board[i][x] in [
"Q",
"R",
]: # can only be hit from up if its a rook or queen
print("YES")
board_checked = True
break # continue bc piece blocks attacks from this direction
i -= 1
if board_checked:
continue
# down
i = y + 1
while i < 8:
if board[i][x] != ".":
if board[i][x] in [
"Q",
"R",
]: # can only be hit from down if its a rook or queen
print("YES")
board_checked = True
break # continue bc piece blocks attacks from this direction
i += 1
if board_checked:
continue
# left up diagonal
i, j = y - 1, x - 1
while i > 0 and j > 0:
if board[i][j] != ".":
if board[i][j] in [
"Q",
"B",
]: # can only be hit drom diagonal if its queen or bishop
print("YES")
board_checked = True
break # continue bc piece blocks attacks from this direction
i -= 1
j -= 1
if board_checked:
continue
# right up diagonal
i, j = y + 1, x - 1
while i < 8 and j >= 0:
if board[i][j] != ".":
if board[i][j] in ["Q", "B"]:
print("YES")
board_checked = True
break
i += 1
j -= 1
if board_checked:
continue
# left down diagonal
i, j = y - 1, x + 1
while i >= 0 and j < 8:
if board[i][j] != ".":
if board[i][j] in ["Q", "B"]:
print("YES")
board_checked = True
break
i -= 1
j += 1
if board_checked:
continue
# right down diagonal
i, j = y + 1, x + 1
while i < 8 and j < 8:
if board[i][j] != ".":
if board[i][j] in ["Q", "B"]:
print("YES")
board_checked = True
break
i += 1
j += 1
if board_checked:
continue
# weird pawn poses
if y < 8:
if x > 0 and board[y + 1][x - 1] == "P":
print("YES")
continue
elif x < 8 and board[y + 1][x + 1] == "P":
print("YES")
continue
# no double step pawn in task
# weird knight poses
# up
if y > 1:
if x > 0 and board[y - 2][x - 1] == "N":
print("YES")
continue
elif x < 8 and board[y - 2][x + 1] == "N":
print("YES")
continue
# down
if y < 6:
if x > 0 and board[y + 2][x - 1] == "N":
print("YES")
continue
elif x < 8 and board[y + 2][x + 1] == "N":
print("YES")
continue
# left
if x > 1:
if y > 0 and board[y - 1][x - 2] == "N":
print("YES")
continue
elif y < 8 and board[y + 1][x - 2] == "N":
print("YES")
continue
# right
if x < 6:
if y > 0 and board[y - 1][x + 2] == "N":
print("YES")
continue
elif y < 8 and board[y + 1][x + 2] == "N":
print("YES")
continue
print("NO")
main()
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 16ms | 3380 KiB | ||||
subtask2 | 0/11 | ||||||
2 | Runtime error | 17ms | 3484 KiB | ||||
3 | Runtime error | 17ms | 3728 KiB | ||||
4 | Runtime error | 17ms | 3572 KiB | ||||
5 | Runtime error | 17ms | 3388 KiB | ||||
subtask3 | 0/12 | ||||||
6 | Runtime error | 17ms | 3508 KiB | ||||
7 | Runtime error | 17ms | 3328 KiB | ||||
8 | Runtime error | 17ms | 3400 KiB | ||||
9 | Runtime error | 17ms | 3384 KiB | ||||
subtask4 | 0/15 | ||||||
10 | Runtime error | 17ms | 3384 KiB | ||||
11 | Accepted | 17ms | 3384 KiB | ||||
12 | Runtime error | 17ms | 3480 KiB | ||||
13 | Runtime error | 18ms | 3384 KiB | ||||
subtask5 | 0/16 | ||||||
14 | Accepted | 17ms | 3376 KiB | ||||
15 | Accepted | 17ms | 3384 KiB | ||||
16 | Runtime error | 17ms | 3384 KiB | ||||
17 | Runtime error | 17ms | 3388 KiB | ||||
subtask6 | 0/46 | ||||||
18 | Accepted | 17ms | 3376 KiB | ||||
19 | Runtime error | 17ms | 3384 KiB | ||||
20 | Runtime error | 17ms | 3396 KiB | ||||
21 | Runtime error | 18ms | 3380 KiB | ||||
22 | Runtime error | 17ms | 3384 KiB | ||||
23 | Runtime error | 17ms | 3584 KiB | ||||
24 | Runtime error | 17ms | 3580 KiB | ||||
25 | Runtime error | 17ms | 3384 KiB | ||||
26 | Runtime error | 17ms | 3568 KiB |