| 11762 | 2024-11-09 15:28:33 | balint | Stefan sakkmesteri ambíciói | python3 | Elfogadva 100/100 | 25ms | 3732 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 < 7:
if x > 0 and board[y + 1][x - 1] == "P":
print("YES")
continue
elif x < 7 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 < 7 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 < 7 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 < 7 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 < 7 and board[y + 1][x + 2] == "N":
print("YES")
continue
print("NO")
main()
| Részfeladat | Összpont | Teszt | Verdikt | Idő | Memória | ||
|---|---|---|---|---|---|---|---|
| subtask1 | 0/0 | ||||||
| 1 | Elfogadva | 16ms | 3384 KiB | ||||
| subtask2 | 11/11 | ||||||
| 2 | Elfogadva | 17ms | 3380 KiB | ||||
| 3 | Elfogadva | 17ms | 3520 KiB | ||||
| 4 | Elfogadva | 18ms | 3372 KiB | ||||
| 5 | Elfogadva | 25ms | 3488 KiB | ||||
| subtask3 | 12/12 | ||||||
| 6 | Elfogadva | 17ms | 3384 KiB | ||||
| 7 | Elfogadva | 17ms | 3384 KiB | ||||
| 8 | Elfogadva | 18ms | 3412 KiB | ||||
| 9 | Elfogadva | 24ms | 3520 KiB | ||||
| subtask4 | 15/15 | ||||||
| 10 | Elfogadva | 17ms | 3576 KiB | ||||
| 11 | Elfogadva | 17ms | 3384 KiB | ||||
| 12 | Elfogadva | 17ms | 3564 KiB | ||||
| 13 | Elfogadva | 24ms | 3384 KiB | ||||
| subtask5 | 16/16 | ||||||
| 14 | Elfogadva | 17ms | 3732 KiB | ||||
| 15 | Elfogadva | 17ms | 3384 KiB | ||||
| 16 | Elfogadva | 17ms | 3384 KiB | ||||
| 17 | Elfogadva | 23ms | 3632 KiB | ||||
| subtask6 | 46/46 | ||||||
| 18 | Elfogadva | 17ms | 3540 KiB | ||||
| 19 | Elfogadva | 17ms | 3520 KiB | ||||
| 20 | Elfogadva | 17ms | 3336 KiB | ||||
| 21 | Elfogadva | 23ms | 3432 KiB | ||||
| 22 | Elfogadva | 24ms | 3384 KiB | ||||
| 23 | Elfogadva | 24ms | 3552 KiB | ||||
| 24 | Elfogadva | 23ms | 3400 KiB | ||||
| 25 | Elfogadva | 21ms | 3540 KiB | ||||
| 26 | Elfogadva | 23ms | 3384 KiB | ||||