117612024-11-09 15:26:46balintStefan sakkmesteri ambícióipython3Hibás válasz 23/10025ms3828 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ÖsszpontTesztVerdiktIdőMemória
subtask10/0
1Elfogadva16ms3384 KiB
subtask211/11
2Elfogadva16ms3576 KiB
3Elfogadva17ms3732 KiB
4Elfogadva17ms3348 KiB
5Elfogadva25ms3640 KiB
subtask312/12
6Elfogadva17ms3384 KiB
7Elfogadva17ms3384 KiB
8Elfogadva17ms3568 KiB
9Elfogadva24ms3636 KiB
subtask40/15
10Elfogadva17ms3568 KiB
11Elfogadva17ms3384 KiB
12Hibás válasz17ms3672 KiB
13Hibás válasz23ms3640 KiB
subtask50/16
14Elfogadva17ms3384 KiB
15Elfogadva17ms3560 KiB
16Elfogadva17ms3388 KiB
17Hibás válasz23ms3640 KiB
subtask60/46
18Elfogadva17ms3376 KiB
19Elfogadva17ms3516 KiB
20Hibás válasz17ms3520 KiB
21Hibás válasz24ms3608 KiB
22Hibás válasz24ms3672 KiB
23Hibás válasz23ms3416 KiB
24Hibás válasz23ms3828 KiB
25Hibás válasz23ms3500 KiB
26Hibás válasz23ms3560 KiB