Skip to content

(22 복습) 삼성 SW 역량 테스트 기출 문제 / 백준 / 17143 / 낚시왕 #138

@sallyy1

Description

@sallyy1
r, c, m = map(int, input().split())

# 배열 정보
a = [ [-1 for col in range(c)] for row in range(r)]




shark = [[] for _ in range(m)]
#      0   1     2      3       4
# [위치_행, 위치_열, 속력, 이동방향, 크기]

for idx in range(m):
    rr, cc, s, d, z = map(int, input().split())
    rr -= 1
    cc -= 1

    shark[idx] = [rr, cc, s, d, z]
    a[rr][cc] = idx

# print(shark[1][4])
# for r_ex in a:
#     print(r_ex)

# 방향 : 없음, 위, 아래, 오른쪽, 왼쪽
dx = [0, -1, 1, 0, 0]
dy = [0, 0, 0, 1, -1]


# 게임 시작
answer = 0 # 잡은 상어 크기의 합
p_col = -1


## 1단계
while p_col < c-1: # -1/0/1/2/3/4/5 일때 까지 다음 스텝 수행
    p_col += 1

    ## 2단계
    for row in range(r):
         if a[row][p_col] != -1:
             now_idx = a[row][p_col]
             answer += shark[now_idx][4]

             # 잡아먹힌 정보 업데이트
             a[row][p_col] = -1
             shark[now_idx] = -1 ###
             break

    ## 3단계
    b = [ [ [] for _ in range(c)] for _ in range(r)]

    # for r_ex in b:
    #     print(r_ex)


    for row in range(r):
        for col in range(c):
            if a[row][col] == -1:
                continue

            idx = a[row][col]

            if shark[idx] == -1:
                print('## {0} 번 상어는 이미 잡아먹혔습니다.'.format(idx))
                continue

            # print('## {0} 번 상어 : 속력 {1} 만큼 이동 시작'.format(idx, shark[idx][2]))
            # print(shark[idx])

            # 오른쪽 또는 왼쪽 이동하는 상어일 때
            if shark[idx][3] == 3 or shark[idx][3] == 4:
                move = shark[idx][2] % (2*c - 2)
            # 위 또는 아래 이동하는 상어일 떼
            else:
                move = shark[idx][2] % (2 * r - 2)


            ## 속도를 주기로 나눈만큼 이동 수행
            x, y = shark[idx][0], shark[idx][1]
            nx, ny = x, y
            #print('## 위치 ({0}, {1})에서 시작, {2} 만큼 총 이동해야 함'.format(row, col, move))


            for n in range(move):
                # 오
                if shark[idx][3] == 3:
                    ny = y + 1
                    if ny == c:
                        ny = ny - 2
                        shark[idx][3] = 4  ##### 업데이트

                # 왼
                elif shark[idx][3] == 4:
                    ny = y - 1
                    if ny == -1:
                        ny = ny + 2
                        shark[idx][3] = 3  ##### 업데이트

                # 위
                elif shark[idx][3] == 1:
                    nx = x - 1
                    if nx == -1:
                        nx = nx + 2
                        shark[idx][3] = 2  ##### 업데이트

                # 아래
                else:
                    nx = x + 1
                    if nx == r:
                        nx = nx - 2
                        shark[idx][3] = 1 ##### 업데이트


                ####print( (row,col), a[row][col], shark[idx], nx, ny)
                x, y = nx, ny ## 업데이트



            b[x][y].append( [idx, shark[idx][4]] ) ## 상어 크기 비교를 위한 정보 저장
            shark[idx][0], shark[idx][1] = x, y ## 상어 위치 정보 업데이트



    # 추가 단계
    copy = [[-1 for _ in range(c)] for _ in range(r)]

    # for line in b:
    #     print(line)
    # print()

    for row in range(r):
        for col in range(c):
            if b[row][col] == []:
                continue

            if len(b[row][col]) == 1:
                copy[row][col] = b[row][col][0][0]

            else:
                ## 실수 주의
                b[row][col].sort(reverse=True, key=lambda x: x[1]) # 상어 크기 역순으로 정렬
                ####print((row,col), b[row][col])
                copy[row][col] = b[row][col][0][0]


    a = copy[:][:]

    # print('##########')
    # print(p_col, ' 열에서 수행한 결과')
    # for line in a:
    #     print(line)



print(answer)

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions