Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

25-SeongHoonC #194

Merged
merged 5 commits into from
May 26, 2024
Merged

25-SeongHoonC #194

merged 5 commits into from
May 26, 2024

Conversation

SeongHoonC
Copy link
Collaborator

@SeongHoonC SeongHoonC commented May 22, 2024

๐Ÿ”— ๋ฌธ์ œ ๋งํฌ

ํ…ŒํŠธ๋กœ๋ฏธ๋…ธ

โœ”๏ธ ์†Œ์š”๋œ ์‹œ๊ฐ„

40 ๋ถ„

โœจ ์ˆ˜๋„ ์ฝ”๋“œ

๋ฐฉ์ง€์šฉ ํŽ˜์Šคํƒ€๊ณ 

image

์ €๋Š” ๊ทธ๋ƒฅ ๋ชจ๋“  ๊ฒฝ์šฐ์˜ ์ˆ˜ ๋‹ค ๋•Œ๋ ค๋„ฃ์—ˆ์Šต๋‹ˆ๋‹ค.

  1. ํ…ŒํŠธ๋กœ๋ฏธ๋…ธ ํ˜•ํƒœ์˜ ๋ชจ๋“  ์ขŒํ‘œ๋ฅผ ์ €์žฅํ•˜๊ตฌ์š”
val t1 = listOf(0 to 0, 0 to 1, 0 to 2, 0 to 3)
val t2 = listOf(0 to 0, 0 to 1, 1 to 0, 1 to 1)
val t3 = listOf(0 to 0, 1 to 0, 2 to 0, 2 to 1)
val t4 = listOf(0 to 0, 1 to 0, 1 to 1, 2 to 1)
val t5 = listOf(0 to 0, 0 to 1, 0 to 2, 1 to 1)
val tetrominos = listOf(t1, t2, t3, t4, t5)
  1. board ๋ฅผ ์ƒ์„ฑํ•ด ๊ฐ ์ˆซ์ž๋ฅผ ๋ฐฐ์—ด์— ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.
  2. ๋ชจ๋“  x, y ๊ธฐ์ค€์œผ๋กœ ํ…ŒํŠธ๋กœ๋ฏธ๋…ธ๋ฅผ ๋†“์„ ์ˆ˜ ์žˆ๋Š”์ง€, ํ•ฉ์€ ๋ช‡์ธ์ง€ ๊ณ„์‚ฐํ•ฉ๋‹ˆ๋‹ค.
  3. ํ…ŒํŠธ๋กœ๋ฏธ๋…ธ๋ฅผ ๋’ค์ง‘๊ณ , ๋Œ๋ฆฌ๋Š” ๊ฒฝ์šฐ์˜ ์ˆ˜๊นŒ์ง€ ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.
    ๋’ค์ง‘๊ธฐ -> x ์ขŒํ‘œ์— * -1
    90๋„ ํšŒ์ „ -> (x,y) -> (y, -x)
  4. ํ•ฉ ์ค‘์—์„œ ์ตœ๋Œ€๊ฐ’์„ ํ”„๋ฆฐํŠธํ•˜๊ณ  ์ข…๋ฃŒํ•ฉ๋‹ˆ๋‹ค.

๊ตฌ๊ต์ˆ˜๋‹˜์ด ๋ฐฑํŠธ๋ž˜ํ‚น์œผ๋กœ ํ’€์—ˆ๋ฐ์š”.

๐Ÿ“š ์ƒˆ๋กญ๊ฒŒ ์•Œ๊ฒŒ๋œ ๋‚ด์šฉ

Copy link

@9kyo-hwang 9kyo-hwang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ใ…“... ์ œ๊ฐ€ ์–ธ์ œ ๊ต์ˆ˜๊ฐ€ ๋˜์—ˆ์„๊นŒ์š”?

์ „ ๋ฐฑํŠธ๋ž˜ํ‚น์œผ๋กœ ํ–ˆ์Šต๋‹ˆ๋‹ค :)

Copy link
Member

@tgyuuAn tgyuuAn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์™€ ์ง„์งœ ์„ฑํ›ˆ๋‹˜ ์ฒ˜๋Ÿผ ํ’€๋ ค๋‹ค๊ฐ€...

์ฐจ๋ผ๋ฆฌ ๋ณด๋“œ๋ฅผ ๋Œ๋ฆฌ๋ฉด ์–ด๋–จ๊นŒ? ํ•ด์„œ ๊ทธ๋ ‡๊ฒŒ ํ’€์—ˆ๋Š”๋ฐ ์ง„์งœ ํ™”๊ฐ€ ๋ฐ•๋ฐ• ๋‚˜๋Š” ๋ฌธ์ œ์˜€์–ด์š”..

๊ทผ๋ฐ ์ด์ œ ๋ณด๋“œ๋ฅผ ๋Œ๋ฆฌ๋Š” ๊ฒƒ ๋ณด๋‹ค ํƒ€์ผ์„ ๋Œ๋ฆฌ๋Š” ๊ฒƒ์ด ์‹œ๊ฐ„ ๋ณต์žก๋„ ๋” ์ด๋“์ผ ๋“ฏ ํ•ด์š”.

deepcopy๋ฅผ ๋ฐ•๋ฐ•์จ์„œ ๊ทธ๋Ÿฐ์ง€ python3์œผ๋กœ๋Š” ํ†ต๊ณผ๊ฐ€ ์•ˆ๋˜๊ณ  pypy3๋กœ๋งŒ ํ†ต๊ณผ๊ฐ€ ๋˜๋„ค์š”..

import sys
from copy import *

def input(): return sys.stdin.readline().rstrip()

N, M = map(int, input().split())
board = []

for _ in range(N):
    board.append(list(map(int,input().split())))

answer = 0
def check(board):
    global answer
    
    for row in range(N):
        for col in range(M):
            # ์ฒซ ๋ฒˆ์งธ ๋„ํ˜•
            if col <= M-4: answer = max(answer, sum(board[row][col:col+4]))
        
            # ๋‘ ๋ฒˆ์งธ ๋„ํ˜•
            if col <= M-2 and row <= N-2: 
                temp = sum(board[row][col:col+2])
                temp += sum(board[row+1][col:col+2])
                answer = max(answer, temp)
            
            # ์„ธ ๋ฒˆ์งธ ๋„ํ˜•
            if col <= M-2 and row <= N-3: 
                temp = board[row][col]
                temp += board[row+1][col]
                temp += sum(board[row+2][col:col+2])
                answer = max(answer, temp)
                
            # ๋„ค ๋ฒˆ์งธ ๋„ํ˜•
            if col <= M-2 and row <= N-3: 
                temp = board[row][col]
                temp += sum(board[row+1][col:col+2])
                temp += board[row+2][col+1]
                answer = max(answer, temp)
            
            # ๋‹ค์„ฏ ๋ฒˆ์งธ ๋„ํ˜•
            if col <= M-3 and row <= N-2: 
                temp = sum(board[row][col:col+3])
                temp += board[row+1][col+1]
                answer = max(answer, temp)
            
for horizontal_reverse in range(2):
    for vertical_reverse in range(2):
        new_board = deepcopy(board)
        
        if horizontal_reverse == 1:
            for row_idx in range(N):
                new_board[row_idx] = new_board[row_idx][-1::-1]
        
        
        if vertical_reverse == 1:
            for row_idx in range(int((N-0.1)/2)+1):
                for col_idx in range(M):
                    new_board[row_idx][col_idx], new_board[N-row_idx-1][col_idx] = new_board[N-row_idx-1][col_idx], new_board[row_idx][col_idx]
                
        for rotation_count in range(4):
            temp_board = []
            
            if rotation_count == 0: check(new_board)
            
            for i in range(rotation_count):
                for inner_col in range(M):
                    now_col = []
                    for inner_row in range(N-1,-1,-1):
                        now_col.append(new_board[inner_row][inner_col])
                        
                    temp_board.append(now_col)

                new_board = temp_board[:]
                temp_board.clear()
                N, M = M, N
                
            check(new_board)
    
print(answer)







๊ทผ๋ฐ ์™ ์ง€ ์ด๊ฑฐ๋ง๊ณ  ๋” ์ข‹์€ ํ’€์ด๊ฐ€ ์žˆ์„ ๊ฒƒ ๊ฐ™์•„์„œ ์„œ์น˜๋ฅผ ํ•ด๋ดค๋Š”๋ฐ DFS๋กœ๋„ ํ’€๋ฆฌ๋„ค์š” ใ…Žใ„ทใ„ทใ„ทใ„ท

@9kyo-hwang ๊ฐœ์ฒœ์žฌ ใ…Žใ„ทใ„ทใ„ทใ„ท

Copy link
Collaborator

@H0ngJu H0ngJu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์•„ ๋ฉฐ์น ๋™์•ˆ ํ‹ˆํ‹ˆ์ด ์ด ๋ฌธ์ œ ํ’€์–ด๋ดค๋Š”๋ฐ .. ์–ด๋ ต๋„ค์š” ...
๊ฒฐ๊ตญ ๊ตฌํ˜„๊นŒ์ง€๋Š” ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค ใ…œใ…œ

์ €๋„ ์ฒ˜์Œ์— 5๊ฐœ์˜ ํ…ŒํŠธ๋ฆฌ์Šค๋ฅผ ์ €์žฅํ•ด๋‘๊ณ , ํšŒ์ „, ๋’ค์ง‘์–ด ๊ฐ€๋ฉด์„œ dfsํ•˜๋ ค๊ณ  ํ–ˆ๋Š”๋ฐ
๋„์ €ํžˆ ๊ฐ์ด ์•ˆ์˜ค๋”๋ผ๊ณ ์š”.. ๐Ÿ˜ญ๐Ÿ˜ญ ์ค‘๊ฐ„์— ํ•˜๋ฉด์„œ๋„ ์ด๊ฒŒ ๋งž๋‚˜..? ๋ผ๋Š” ์ƒ๊ฐ์ด ๋“ค์–ด์„œ

๊ทธ๋ƒฅ ๋ชจ๋“  ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ tetris ๋กœ ์ €์žฅํ•ด๋‘๊ณ  ๊บผ๋‚ด ์“ฐ๋ ค๊ณ  ํ–ˆ์Šต๋‹ˆ๋‹ค (์•„๋ž˜ ์ฝ”๋“œ์ž…๋‹ˆ๋‹ค)
ํ•˜์ง€๋งŒ ๊ฒฐ๊ณผ๋Š” ์‹คํŒจ์˜€๊ตฌ์š” ...ใ…Ž...

๊ทธ๋ž˜์„œ ์„ฑํ›ˆ๋‹˜ PR + ๊ตํ™ฉ๋‹˜ PR + ๋ธ”๋กœ๊ทธ ๊ธ€ ๋ณด๋ฉด์„œ ์ดํ•ดํ–ˆ์Šต๋‹ˆ๋‹ค

๋‹ค์Œ์— ๋‹ค์‹œ ํ•œ๋ฒˆ ๋” ํ’€์–ด๋ด์•ผ๊ฒ ๋„ค์š” ใ…œ.ใ…œ
์ข‹์€ ๋ฌธ์ œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค ๐Ÿ˜ญ๐Ÿ‘๐Ÿ‘

import sys

def input(): return sys.stdin.readline().rstrip()

N, M = map(int, input().split())

arr = [list(map(int, input().split())) for _ in range(N)]
visited = [[0 for _ in range(M)] for _ in range(N)]
polionomino = [[0 for _ in range(M)] for _ in range(N)]
direc = [(1,0),(-1,0),(0,1),(0,-1)]

tetris = [
    [(0,0), (0,1), (0,2), (0,3)], [(0,0), (1,0), (2,0), (3,0)],  # ใ…ก
    [(0,0), (0,1), (1,0), (1,1)],                               # ใ…
    [(0,0), (1,0), (2,0), (2,1)], [(0,0), (1,0), (2,0), (2,-1)], # L
    [(0,0), (0,1), (0,2), (1,0)], [(0,0), (0,1), (0,2), (1,2)],  # L
    [(0,0), (1,0), (1,1), (1,2)], [(0,0), (0,1), (1,0), (2,0)],  # L
    [(1,0), (1,1), (1,2), (0,2)], [(0,0), (0,1), (1,1), (2,1)],  # L
    [(0,0), (0,1), (1,1), (1,2)], [(0,1), (1,1), (1,0), (2,0)],  # z
    [(0,0), (1,0), (1,1), (2,1)], [(0,1), (1,0), (1,1), (0,2)],  # Z
    [(0,0), (0,1), (0,2), (1,1)], [(0,0), (1,0), (2,0), (1,1)],  # ใ…“
    [(0,1), (0,1), (1,1), (2,1)], [(0,0), (1,0), (1,1), (2,0)],  # ใ…“
]

def can_put(x, y, shape):
    for ax, ay in shape:
        nx = x + ax
        ny = y + ay
        if nx < 0 or nx >= N or ny < 0 or ny >= M:
            return False
    return True

def put_tetris(x, y):
    tmp_sum = 0

    for shape in tetris:
        if can_put(x, y, shape):
            c_sum = 0
            for ax, ay in shape:
                nx = x + ax
                ny = y + ay
                c_sum += arr[nx][ny]
            tmp_sum = max(tmp_sum, c_sum)

    return tmp_sum

def solution():
    max_sum = 0
    for i in range(N):
        for j in range(M):
            max_sum = max(max_sum, put_tetris(i, j))
    print(max_sum)

solution()

@tgyuuAn
Copy link
Member

tgyuuAn commented May 25, 2024

์•„ ๋ฉฐ์น ๋™์•ˆ ํ‹ˆํ‹ˆ์ด ์ด ๋ฌธ์ œ ํ’€์–ด๋ดค๋Š”๋ฐ .. ์–ด๋ ต๋„ค์š” ... ๊ฒฐ๊ตญ ๊ตฌํ˜„๊นŒ์ง€๋Š” ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค ใ…œใ…œ

์ €๋„ ์ฒ˜์Œ์— 5๊ฐœ์˜ ํ…ŒํŠธ๋ฆฌ์Šค๋ฅผ ์ €์žฅํ•ด๋‘๊ณ , ํšŒ์ „, ๋’ค์ง‘์–ด ๊ฐ€๋ฉด์„œ dfsํ•˜๋ ค๊ณ  ํ–ˆ๋Š”๋ฐ ๋„์ €ํžˆ ๊ฐ์ด ์•ˆ์˜ค๋”๋ผ๊ณ ์š”.. ๐Ÿ˜ญ๐Ÿ˜ญ ์ค‘๊ฐ„์— ํ•˜๋ฉด์„œ๋„ ์ด๊ฒŒ ๋งž๋‚˜..? ๋ผ๋Š” ์ƒ๊ฐ์ด ๋“ค์–ด์„œ

๊ทธ๋ƒฅ ๋ชจ๋“  ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ tetris ๋กœ ์ €์žฅํ•ด๋‘๊ณ  ๊บผ๋‚ด ์“ฐ๋ ค๊ณ  ํ–ˆ์Šต๋‹ˆ๋‹ค (์•„๋ž˜ ์ฝ”๋“œ์ž…๋‹ˆ๋‹ค) ํ•˜์ง€๋งŒ ๊ฒฐ๊ณผ๋Š” ์‹คํŒจ์˜€๊ตฌ์š” ...ใ…Ž...

๊ทธ๋ž˜์„œ ์„ฑํ›ˆ๋‹˜ PR + ๊ตํ™ฉ๋‹˜ PR + ๋ธ”๋กœ๊ทธ ๊ธ€ ๋ณด๋ฉด์„œ ์ดํ•ดํ–ˆ์Šต๋‹ˆ๋‹ค

๋‹ค์Œ์— ๋‹ค์‹œ ํ•œ๋ฒˆ ๋” ํ’€์–ด๋ด์•ผ๊ฒ ๋„ค์š” ใ…œ.ใ…œ ์ข‹์€ ๋ฌธ์ œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค ๐Ÿ˜ญ๐Ÿ‘๐Ÿ‘

import sys

def input(): return sys.stdin.readline().rstrip()

N, M = map(int, input().split())

arr = [list(map(int, input().split())) for _ in range(N)]
visited = [[0 for _ in range(M)] for _ in range(N)]
polionomino = [[0 for _ in range(M)] for _ in range(N)]
direc = [(1,0),(-1,0),(0,1),(0,-1)]

tetris = [
    [(0,0), (0,1), (0,2), (0,3)], [(0,0), (1,0), (2,0), (3,0)],  # ใ…ก
    [(0,0), (0,1), (1,0), (1,1)],                               # ใ…
    [(0,0), (1,0), (2,0), (2,1)], [(0,0), (1,0), (2,0), (2,-1)], # L
    [(0,0), (0,1), (0,2), (1,0)], [(0,0), (0,1), (0,2), (1,2)],  # L
    [(0,0), (1,0), (1,1), (1,2)], [(0,0), (0,1), (1,0), (2,0)],  # L
    [(1,0), (1,1), (1,2), (0,2)], [(0,0), (0,1), (1,1), (2,1)],  # L
    [(0,0), (0,1), (1,1), (1,2)], [(0,1), (1,1), (1,0), (2,0)],  # z
    [(0,0), (1,0), (1,1), (2,1)], [(0,1), (1,0), (1,1), (0,2)],  # Z
    [(0,0), (0,1), (0,2), (1,1)], [(0,0), (1,0), (2,0), (1,1)],  # ใ…“
    [(0,1), (0,1), (1,1), (2,1)], [(0,0), (1,0), (1,1), (2,0)],  # ใ…“
]

def can_put(x, y, shape):
    for ax, ay in shape:
        nx = x + ax
        ny = y + ay
        if nx < 0 or nx >= N or ny < 0 or ny >= M:
            return False
    return True

def put_tetris(x, y):
    tmp_sum = 0

    for shape in tetris:
        if can_put(x, y, shape):
            c_sum = 0
            for ax, ay in shape:
                nx = x + ax
                ny = y + ay
                c_sum += arr[nx][ny]
            tmp_sum = max(tmp_sum, c_sum)

    return tmp_sum

def solution():
    max_sum = 0
    for i in range(N):
        for j in range(M):
            max_sum = max(max_sum, put_tetris(i, j))
    print(max_sum)

solution()

์™€ํ์ฃผ ์ตœ๊ณ  ์ตœ๊ณ ~

@alstjr7437
Copy link
Member

์ €๋„ ํ•ด๋‹น ๋ฌธ์ œ๋ฅผ ๊ฒน์น˜๋Š” ๋ถ€๋ถ„์„ ์ž˜๋ชป ์„ ์ •ํ•˜์—ฌ์„œ...
๋ฏธ๋ฆฌ์บ”๋ฒ„์Šค์— ๊ฐ ๋ชจ์–‘์„ ์ €์žฅํ•ด๋‘๋ฉด์„œ ํ•˜๋ ค๊ณ  ํ–ˆ๋Š”๋ฐ ๊ฒน์ณ์„œ ๋ฐ”๊พธ๊ฒŒ ๋˜์—ˆ๊ตฐ์š”...!

image
tetromino = [
    [(0, 0), (0, 1), (1, 0), (1, 1)], 
    [(0, 0), (0, 1), (0, 2), (0, 3)], 
    [(0, 0), (1, 0), (2, 0), (3, 0)], 
    [(0, 0), (0, 1), (0, 2), (1, 0)],
    [(1, 0), (1, 1), (1, 2), (0, 2)],
    [(0, 0), (1, 0), (1, 1), (1, 2)], 
    [(0, 0), (0, 1), (0, 2), (1, 2)], 
    [(0, 0), (1, 0), (2, 0), (2, 1)],
    [(2, 0), (2, 1), (1, 1), (0, 1)],
    [(0, 0), (0, 1), (1, 0), (2, 0)],
    [(0, 0), (0, 1), (1, 1), (2, 1)],
    [(0, 0), (0, 1), (0, 2), (1, 1)],  
    [(1, 0), (1, 1), (1, 2), (0, 1)],
    [(0, 0), (1, 0), (2, 0), (1, 1)], 
    [(1, 0), (0, 1), (1, 1), (2, 1)],  
    [(1, 0), (2, 0), (0, 1), (1, 1)],
    [(0, 0), (1, 0), (1, 1), (2, 1)],
    [(1, 0), (0, 1), (1, 1), (0, 2)],
    [(0, 0), (0, 1), (1, 1), (1, 2)]
]

๊นŒ์ง€ ๋ธŒ๋ฃจํŠธํฌ์Šค๋กœ ์„ธ์›Œ๋‘๊ณ  ํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ํ’€๋ ค๊ณ  ํ–ˆ๋Š”๋ฐ ๊ฒน์ณ์„œ ๋ฉˆ์ถฐ ๋ฒ„๋ ธ๊ตฐ์š”..
๋‹ค์Œ์— ์‹œ๊ฐ„์ด ๋˜๋ฉด DFS๋กœ ํ•œ๋ฒˆ ํ’€์–ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants